-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Declaration of Carbon\Translator after Laravel 7 Upgrade #2033
Comments
Please triple-check you're really running PHP >= 7.2. This error message is supposed to happen when Symfony >= 5 has been installed and is executed with PHP <= 7.1. Remember the CLI version of PHP may be different from the version ran in Apache, FastCGI, etc. So what If your production/remote environment run PHP <= 7.1, you simply can't use Symfony 5 or Laravel 7 on this environment and have to upgrade your PHP version or pick a lower version of Symfony/Laravel. Note that config.platform.php composer setting won't work if the chosen version is greater than the PHP version running in production/remote environment. Last, code cache like OPCache should be cleaned/regenerated on deploy, or at least on deploy after an upgrade of important dependencies such as your framework. |
I'm really surprise this throws an exception as our unit tests for Translator::trans succeed using PHP 7.3 and Symfony 5.0.5: |
Could you please try to provide an minimum code chunk to reproduce the Carbon issue outside Laravel? |
Won't fixing the declaration mean forcing the use of Update I think I figured it out. Tinkerwell is not using the same PHP binary as my system. After pointing Tinkerwell to the correct version (7.3.13) it started working. 🤦♂ |
On the contrary, the declaration is currently covariant (it's valid and the unit tests are passing for all versions), if I update the declaration to be exactly the same as the current 5.0 implementation, it will break Symfony < 5. You always need to be sure that composer run the same PHP version when it installs the dependencies that the one your run for the webserver and indeed I guess the issue is the same for @stevenhardy-digital. |
This occurs also to me.
But still getting those errors.
|
Basically it's line 314 in Translator.php. |
As you can see there: https://travis-ci.org/github/kylekatarnls/Carbon/builds/659770462 Aligning the typehint will break Symfony < 5 compatibility and PHP < 7.2 compatibility and as you can see here: https://travis-ci.org/github/kylekatarnls/Carbon/builds/659768977 The library on its own with the current typing is compatible with all versions of PHP and Symfony. So I won't break anything until I have the exact cause of the error (a way to reproduce it in a sandbox with Carbon alone). Mabe FastCGI behaves differently regarding typing covariance. Can you compare with standard PHP ( Or does someone get the same error without FastCGI? (In Apache maybe?) |
Hi all, PHP version: 7.4.0 Error: Laravel 500 with below error log:
But my environment is a bit special, I am not running Laravel on Apache / FastCGI / PHP-FPM, etc. However, my workaround is forked this repository, add typehint to both Translator::trans() and Translator::setLocale() by follow Symfony 5, and use composer VCS to require my own Carbon package to my project, now everything is good for my own project. I know that is a bad idea, but I can't do anything if I don't do that. If anyone facing same issue, can consider to use this workaround too. Agree @kylekatarnls 's point, that will break Symfony < 5 compatibility and PHP < 7.2 compatibility. Therefore, I don't submit PR, just solve my own issue first. |
As proven by Travis-CI (and many successful Laravel 7 deployments), Carbon implement is compatible with PHP 7.2 to 7.4 and Symfony 3.4 to 5 : See this code: https://3v4l.org/FnW20 Please try this simple chunk on your own environment. If your PHP program works as expected (respect the PHP documentation and source code) it should not throw any declaration compatibility error. I (and most libraries) use PHP standard CLI to test their library and consider than if a bug occurs in some environment but not in the CI platform (Travis-CI for Carbon) then it's an environment issue. As soon as someone could provide a way to reproduce the bug (using a particular settings, PHP implementation, dependency list) then I would be able to add the bug to our tests and fix it without breaking their app to other users. |
For the record, this message "Declaration of ... must be compatible" is the one you were supposed to see before covariance was introduced (PHP < 7.2), but with PHP < 7.2, composer install Symfony 3 or 4 but not 5 which requires PHP >= 7.2. So if you have this error, you should double-check you are really running the composer installation and the environment that throws the exception with the same PHP version. |
Regarding the lack of elements that would allow to reproduce the bug in a CLI environment or could confirm it really happen with PHP >= 7.2, I close this issue. Please refer #2033 (comment) If you get this error message, there are great chances you're not running the PHP version you think, you're more likely running a PHP version lower than 7.2, and so that is actually not compatible with Laravel 7 / Symfony 5. If sufficient clues may be provided there is a different issue, I will re-open this issue. |
I am using Apache2 with PHP 7.4.8 and I am having the exact same issue where setLocale is incompatible with the parent |
The possible causes and solutions have been given yet: #2033 (comment) |
Yeah, I realized afterwards. Once I fixed everything so that it was actually running on PHP 7.4 all was good again |
Hello,
I encountered an issue with the following code:
Carbon version: 2.31.0
PHP version: 7.3.9
I expected to get:
But I actually get:
Thanks!
The text was updated successfully, but these errors were encountered: