39

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)

5
  • Fresh installation -- you didn't modify anything? What is the language set to in config/app.php? Commented Nov 21, 2019 at 13:03
  • @JeremyHarris Yes completely fresh installation. The default language is 'en' Commented Nov 21, 2019 at 13:04
  • Same issue just after building today Commented Nov 21, 2019 at 19:58
  • 1
    What version of PHP are you running? Commented Nov 21, 2019 at 21:32
  • I have the same error here. It's a bigger project which runs fine locally on windows xampp. One week ago it also had no error on the server (centOS like cloud hosting OS). Today i copied the project 1:1 to the server (including vendor folder) and had this error on the server then. Also composer reinstall doesnt help. Local: Windows, PHP 7.2.11, works. Server: centOS like, PHP 7.2.24, this error. Commented Nov 22, 2019 at 12:51

7 Answers 7

56

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

Sign up to request clarification or add additional context in comments.

1 Comment

Using PHP 7.2 also solved the problem for me without adding the "symfony/translation": "4.3.8"
44

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

2 Comments

I want to confirm this is the easiest and best method. Rolled mine back this morning after having issues last night and fixed it without editing any files. There is a defect in the 4.4 version of Symfony.
"symfony/translation": "4.3.8" not "symfony\translation": "4.3.8"
15

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

1 Comment

Maybe it is a bug I guess. Still, I don't know the reason behind this.
1

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.

3 Comments

If 4.4.X requires php 7.2.5+, Composer shouldn't download the latest version if the current PHP version is less than 7.2.5, isn't it?
Yes, you are right. Composer should download the package which is supported in the current PHP version.
Not true. On the server, I am using php7.3 and I still got this error
1

Updating my PHP version to 7.3 works for me.

Comments

-1

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

Comments

-1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.