Home » Php » php – Symfony\Component\Debug\Exception\FatalErrorException laravel Error

php – Symfony\Component\Debug\Exception\FatalErrorException laravel Error

Posted by: admin April 23, 2020 Leave a comment

Questions:

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)

How to&Answers:

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

Answer:

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).

Answer:

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

Answer:

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.

Answer:

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

Answer:

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