简体   繁体   中英

Symfony\Component\Debug\Exception\FatalErrorException laravel Error

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

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

On my server following were configurations:

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

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

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

and then

composer update

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

composer update --ignore-platform-reqs

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

I solved this issue with "symfony/translation": "4.3.8" in my 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).

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

and delete string keyword from the setLocale() function.

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)

Just navigate to:

vendor/symfony/translation-contracts/TranslatorInteface.php

and delete all the string keywords from the trans() function

--EDIT--

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

"symfony/translation": "4.3.8",

Then open your terminal and type this:

composer update

It is not a bug.

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

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

On my server following were configurations:

PHP 7.2 Laravel Framework 6.*

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

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

and then

composer update

Updating my PHP version to 7.3 works for me.

"symfony/translation": "4.3.8" in composer.json, Its helped me.!!Thanks a lot.

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

 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

Update your PHP version. This often comes as a result of running composer update with a different version of PHP.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM