Skip to content
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

transChoice method is deprecated in Symfony 4.2 #1548

Closed
robbydooo opened this issue Dec 13, 2018 · 13 comments
Closed

transChoice method is deprecated in Symfony 4.2 #1548

robbydooo opened this issue Dec 13, 2018 · 13 comments

Comments

@robbydooo
Copy link

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!

@kylekatarnls
Copy link
Collaborator

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

@kylekatarnls
Copy link
Collaborator

Before doing a painful or radical choice, I will discuss it with Symfony staff: symfony/symfony#29607

@kylekatarnls
Copy link
Collaborator

Hi, @robbydooo, regarding new information provided in symfony/symfony#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.

@robbydooo
Copy link
Author

robbydooo commented Dec 14, 2018

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.

@kylekatarnls
Copy link
Collaborator

Good news so we have enough time to handle properly this deprecation. Thanks for your investigation.

@flaushi
Copy link

flaushi commented Dec 23, 2019

Just a question: If I want to upgrade to symfony 5, then Carbon will be incompatible here? transChoice is gone in sf 5...

@kylekatarnls
Copy link
Collaborator

Symfony 5 is fully supported since the version 2.27.0 thanks to #1937

And transChoice has already been replaced.

@flaushi
Copy link

flaushi commented Dec 23, 2019

And transChoice has already been replaced.

Hmm, I still do get deprecation messages, although I am using 2.27.0

@kylekatarnls
Copy link
Collaborator

It's because you're not on Symfony 5

@flaushi
Copy link

flaushi commented Dec 23, 2019

Thank you!

@xabbuh
Copy link
Contributor

xabbuh commented Dec 23, 2019

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.

@kylekatarnls
Copy link
Collaborator

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.

@xabbuh
Copy link
Contributor

xabbuh commented Feb 21, 2020

@kylekatarnls see #2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants