framework: 5.5.39 breaks in PHP 7.0.10 - Symfony\Component\Translation constructor doesn't work with PHP 7.0.x

  • Laravel Version: 5.5.39
  • PHP Version: 7.0.10
  • Database Driver & Version: MySQL 5.5.56-MariaDB

Description:

This version of Laravel (5.5.39) seems to break support for PHP 7.0.x

Symfony\Component\Translation\Translator.php (1/1) FatalThrowableErrorParse error: syntax error, unexpected ‘?’, expecting variable (T_VARIABLE)

line 79: public function __construct(?string $locale, MessageFormatterInterface $formatter = null, string $cacheDir = null, bool $debug = false)

Steps To Reproduce:

Anywhere Carbon->diffForHumans() is called, this seems to cause the error

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 10
  • Comments: 62 (25 by maintainers)

Most upvoted comments

for now to fix it i had to run this

composer require nesbot/carbon=1.29.*

This happens when you install/update Laravel 5.5 with PHP >7.0.

Did you copy your Laravel installation from a system running PHP 7.1/7.2 to a system running PHP 7.0?

No there is no issue from the package, you just need to install and run your project with the same PHP version. The problem has been explained yet. If you install your dependencies using PHP 7.1, composer will install symfony/translation version 4, if you try to copy your vendor in a 7.0 or older version of PHP, symfony/translation will not be compatible with it.

So you must install your dependencies using PHP 7.0 (or forcing the setting with config.platform.php in your composer.json) then it will install symfony/translation version 3 (which does not contains ?string and does not fail on PHP 7.0)

Hi, it’s a particular failure with Carbon 1.30.0, Laravel < 5.6 and symfony/translation < 4, we’ll patch it today in the 1.31.1. Meanwhile you can test with composer require nesbot/carbon=dev-master

With the last patch released (1.31.1), the locale auto-update is disabled for symfony/translation < 3, so you can update to this version with no error.

We’ll try to support both the auto-update and symfony/translation 3 in the next version.

IM getting this error and i am using PHP 7.0 which i need to as we do not have control over the live server and PHP update for that. So whats the alternative to updating the php version?

I have just recently updated (laravel project) to get this error, never had it previously. I believe the only updated since last week that come in was for Carbon ?

how to solve this?

I migrated from 5.4 PHP 7.0 to

PHP 7.1.15 Laravel Framework 5.5.39

for now to fix it i had to run this

composer require nesbot/carbon=1.29.*

It worked for me … Thanks buddy !

First remove your composer.lock if it exists. Then install with --no-dev to ignore dev dependencies.

Now check your dependencies:

      "barryvdh/laravel-debugbar":"~2.4",
      "cviebrock/eloquent-sluggable":"^4.2.5",
      "guzzlehttp/guzzle":"~6.0",
      "laravel/framework":"5.4.*",
      "laravel/tinker":"~1.0"`

To see if they are all compatible with PHP 7.0. If you want to run your app safely with PHP 7.0 you can’t install libvraries that depends on PHP 7.1+.

I quickly checked your dependencies and they seem compatible with PHP 7.0 (if the composer.json of each of those depdencies are correct) so I guess the problem is just the composer.lock file.

You have "symfony/translation", "version": "v4.0.6",, and it’s not compatible with PHP 7.0. That’s your problem. You must run composer install with a PHP 7.0 program (to be ISO with your prod env), so it will install symfony/translation 3 and will run with PHP 7.0 on prod.

There is nothing wrong here with laravel, carbon or symfony/translation, neither with diffForHumans, it’s just than diffForHumans will load the translator, so it reveals the incompatibility. But the incompatibility is there because your install a library that need PHP 7.1 on a machine that run PHP 7.0.

You should use the same PHP version in development and production to prevent problems like this. It’s possible to use Homestead with older PHP versions.

We will probably need more details: “with php 7”, it’s very wide, the exact version please.

Now, if you cannot run any command in your host, you theoretically have a lot of incompatibility if the machine that install dependencies has different PHP version, extensions etc. than your host. That’s not how you’re supposed to do it when you use composer. Because vendor content will not be the same for a given composer.json for any machine that run the install.

Then please provide your composer.json and composer.lock (ensure there are in line with the actual vendor directory).

OK, as you have a lower version of Laravel (5.4) it could be possible indeed you run into an other issue. Try first to run composer clear-cache and composer update to be sure to get last version of Carbon, then check the version you have with composer show nesbot/carbon

Ah, yes, I understand now. Sorry - we have the vendor folder in git because our prod and qa servers are pretty heavily firewalled, and composer can’t do what it needs.

I will run this on a dev machine running 7.0.x

Thanks!