Hello,
I encountered an issue with the following code:
echo $post->approved_date->diffForHumans();
Carbon version: 1.36
PHP version: 7.2
Laravel 5.7
I expected to get:
2 Months ago
But I actually get:
ErrorException: The "Symfony\Component\Translation\Translator::transChoice()" method is deprecated since Symfony 4.2, use the trans() one instead with a "%count%" parameter.
Error is from /app/vendor/nesbot/carbon/src/Carbon/Carbon.php:4233
Only started happening in the past 48 hours after doing a composer update on my laravel project.
I would do a pull request but I don't know the translation library well enough to know what exactly is happening here.
Let me know if you need any further information.
Thanks!
Hi,
symfony/translation recently deprecated a method we use from it. And by default in Laravel any notice even deprecation will stop the process throwing an exception.
Symfony let us no choice, all existing version of Carbon are incompatible with symfony/translation 4.2, so we have to publish new version (1.37 and 2.8) using the new translation method.
Meanwhile, you can force downgrade symfony/translation:
composer require symfony/translation:~4.1
Before doing a painful or radical choice, I will discuss it with Symfony staff: https://github.com/symfony/symfony/issues/29607
Hi, @robbydooo, regarding new information provided in https://github.com/symfony/symfony/issues/29607 I put this on hold and will not change Carbon until having a way to reproduce it and see if carbon or symfony really do something invalid.
Hi @kylekatarnls I have been reading this, thanks for looking into this.
Based on the comments in that discussion i have looked into the reporting service we use which is HoneyBadger and it appears that there must be an issue in this file
https://github.com/honeybadger-io/honeybadger-php/blob/c6747a54c3ac7b788bbf8a7398011e5e49a62317/src/Handlers/ErrorHandler.php
If i disable the error handling it no longer reports the issue.
I will open up a bug with Honeybadger. Apologies for opening this bug on here although the reporting of the error was originating from Carbon so this was pretty well hidden.
Good news so we have enough time to handle properly this deprecation. Thanks for your investigation.
Just a question: If I want to upgrade to symfony 5, then Carbon will be incompatible here? transChoice is gone in sf 5...
Symfony 5 is fully supported since the version 2.27.0 thanks to https://github.com/briannesbitt/Carbon/pull/1937
And transChoice has already been replaced.
And
transChoicehas already been replaced.
Hmm, I still do get deprecation messages, although I am using 2.27.0
It's because you're not on Symfony 5
Thank you!
I think a better solution would be not to check for the transChoice() to exist to decide which method to call, but to use something else to decide whether or not calling the method would trigger a deprecation.
You mean a solution compatible from Symfony 3 to 5? If you know such a solution, feel free to submit a PR to show concretely what you mean and please provide some details about pros and cons of the solution.
From Carbon point of view, we required required Symfony ^4 (assuming semantic versioning) and start using transChoice() as it was not deprecated. Then Symfony deprecated it since 4.2.
So it seems Symfony consider deprecation can be added in any minor version, which means you should not worry about deprecation if you don't plan to upgrade to the next major version. Either you consider it as a breaking change, but in this case, the change does not come from Carbon but from Symfony.
Note than an other valid option for Carbon could be to not support Symfony 5 or drop completely Symfony 4 to support only Symfony 5 in a next minor or major release. In this case, if you chose to continue to use Symfony 4 you would have been locked on the previous Carbon version and you would also have the deprecation notice despite if would have been a correct way (regarding semver) upgrade.
@kylekatarnls see #2019