php Symfony\Component\Debug\Exception\FatalErrorException laravel 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58975559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 08:36:20  来源:igfitidea点击:

Symfony\Component\Debug\Exception\FatalErrorException laravel Error

phplaravel

提问by Kuldeep Raj

I am getting this error on my new Laravel project. I am trying to run after a fresh installation.

我在我的新 Laravel 项目中遇到此错误。我正在尝试在全新安装后运行。

Declaration of Symfony\Component\Translation\TranslatorInterface::setLocale($locale) must be compatible with Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale)

Symfony\Component\Translation\TranslatorInterface::setLocale($locale) 的声明必须与 Symfony\Contracts\Translation\LocaleAwareInterface::setLocale(string $locale) 兼容

回答by zarpio

On my server following were configurations:

在我的服务器上,以下是配置:

PHP 7.1.26-1+ubuntu14.04.1+deb.sury.org+1 Laravel Framework 5.7.28

PHP 7.1.26-1+ubuntu14.04.1+deb.sury.org+1 Laravel 框架 5.7.28

Solution:Added "symfony/translation": "4.3.8"in composer.jsonas follows

解决方法:"symfony/translation": "4.3.8"composer.json中添加 如下

"require": {
     ...
     "symfony/translation": "4.3.8",
}

and then

进而

composer update

or (if php version is not recommended on the server)

或者(如果服务器上不推荐使用php版本)

composer update --ignore-platform-reqs

作曲家更新 --ignore-platform-reqs

回答by Julien Moulin

I got the same error on PHP 7.2.3 after composer update(symfony\translation v4.3.8 => v4.4.0).

composer update(symfony\translation v4.3.8 => v4.4.0)之后,我在 PHP 7.2.3 上遇到了同样的错误。

I solved this issue with "symfony/translation": "4.3.8"in my composer.json.

"symfony/translation": "4.3.8"在我的 composer.json 中解决了这个问题。

It's a bad idea to hard edit vendors files.

硬编辑供应商文件是一个坏主意。

--

——

Edit:

编辑:

Symfony doc says Install PHP 7.2.5 or higher, so if you don't want to add this restriction into your composer.json file, you can upgrade your PHP version to 7.2.5+ (check others libraries compatibility first).

Symfony 文档说安装 PHP 7.2.5 或更高版本,因此如果您不想将此限制添加到您的 composer.json 文件中,您可以将您的 PHP 版本升级到 7.2.5+(首先检查其他库的兼容性)。

回答by Lokendra Soni

I got the same error today and I solved it with a little editing. Just do this:
Navigate to

我今天遇到了同样的错误,我通过一些编辑解决了它。只需这样做:
导航到

vendor/symfony/translation-contracts/LocaleAwareInteface.php
供应商/symfony/translation-contracts/LocaleAwareInteface.php

and delete stringkeyword from the setLocale()function.

stringsetLocale()函数中删除关键字。

If you get this error after this:

如果您在此之后收到此错误:

Declaration of Symfony\Component\Translation\Translator::trans($id, array $parameters = Array, $domain = NULL, $locale = NULL) must be compatible with Symfony\Contracts\Translation\TranslatorInterface::trans(string $id, array $parameters = Array, ?string $domain = NULL, ?string $locale = NULL)

Symfony\Component\Translation\Translator::trans($id, array $parameters = Array, $domain = NULL, $locale = NULL) 的声明必须兼容 Symfony\Contracts\Translation\TranslatorInterface::trans(string $id , 数组 $parameters = 数组, ?string $domain = NULL, ?string $locale = NULL)

Just navigate to:

只需导航到:

vendor/symfony/translation-contracts/TranslatorInteface.php

供应商/symfony/translation-contracts/TranslatorInteface.php

and delete all the stringkeywords from the trans()function

stringtrans()函数中删除所有关键字

--EDIT--

- 编辑 -

If you don't want to edit vendor files, you can use this:Open your composer.json file, and add this in "require"

如果您不想编辑供应商文件,可以使用:打开您的 composer.json 文件,并将其添加到"require"

"symfony/translation": "4.3.8",

"symfony/translation": "4.3.8",

Then open your terminal and type this:

然后打开你的终端并输入:

composer update

作曲家更新

回答by Abhinav Saraswat

It is not a bug.

这不是一个错误。

The latest version of symfony packages requires PHP version to be at-least 7.2.5

最新版本的 symfony 软件包要求 PHP 版本至少为 7.2.5

Change the PHP version to 7.2.5 or greater and it should work.

将 PHP 版本更改为 7.2.5 或更高版本,它应该可以工作。

回答by VishalParkash

I found simple solution to this problem after roaming google so long. If it could help someone. Upgrading your PHP Version to 7.2 or more

在 google 漫游了这么久之后,我找到了解决这个问题的简单方法。如果它可以帮助某人。将您的 PHP 版本升级到 7.2 或更高版本

 1. sudo a2dismod phpX(X is less than 7.2 version) 
 2. sudo a2enmod php7.2(could be greater than or equal to 7.2)
 3. service apache2 restart

Following these steps should help you getting rid of this issue

遵循这些步骤应该可以帮助您摆脱这个问题

回答by Alex

On my server following were configurations:

在我的服务器上,以下是配置:

PHP 7.2 Laravel Framework 6.*

Solution: Added "symfony/translation": "4.3.8"in composer.jsonas follows

解决方法:在composer.json中添加"symfony/translation":"4.3.8"如下

"require": {
     ...
     "symfony/translation": "4.3.8",
}

and then

进而

composer update