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
[RFC] Fixing Deprecation Warnings #14900
Conversation
👍 had numerous deprecated warnings after upgrading to 2.7 and this PR solved all of them. |
The deprecation warnings are triggered intentionally to let you know what you need to change in your code to be forward compatible with Symfony 3.0. You could silence them by changing your project's |
This PR may be a good idea in fact don't you think? |
The most profound PR I've ever seen. A must merge. 👍 |
@nicolas-grekas Not sure if I understand. Which issue would this change actually solve? |
It switches deprecation notices from opt-out to opt-in |
Yeah, but is that really a good idea? I bet that many people then will never know about this and that they will be surprised when their apps break on Symfony 3.0. Not sure if that's a good experience either. |
I think it is a good idea. @deprecated tags are sufficient, but calling trigger_error() is very shouty. Googling most of the deprecated errors that come out result in most cases with the people discussing end suggesting and / or agreeing that muting E_DEPRECATED in php.ini is the best solution. If the intent is to get people to prepare for 3.0 then, well people aren't. Instead they are just muting the warnings. Further more, for upgraders, seeing the messages for the first time, diagnosing / solving them the correct way is very difficult as google has little to offer in the way of answers. Perhaps some of the deprecated calls don't actually have future ready implementations in place yet. I believe this was the case with the Form components OptionResolverInterface, which my IDE informs me was deprecated in (I think it was) 2.5 or so, but no alternative was provided until something like 2.6 (with OptionResolver). |
Still thinking about it, I really like the idea. I'm 👍 |
@reecefowell can you please enhance the commit message? |
@@ -224,7 +224,7 @@ class JsonSerializableObject implements \JsonSerializable | |||
{ | |||
public function jsonSerialize() | |||
{ | |||
trigger_error('This error is expected', E_USER_WARNING); | |||
@trigger_error('This error is expected', E_USER_WARNING); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one is not a deprecation, please revert and ensure that you silence only deprecations
@nicolas-grekas are these deprecation warnings still reported in the logs after being muted or no ? And does the silencing add some overhead or no ? |
Yes, the debug handler ignores silencing for deprecations. The overhead is
not significant at all.
|
ping @symfony/deciders If we agree on this one, I'd like to merge ASAP for at least two reasons:
|
So this only changes that the deprecation warnings are ignored in production, or? |
Yes, by default |
@@ -170,7 +170,7 @@ public function testDeprecatedSuper($class, $super, $type) | |||
{ | |||
set_error_handler('var_dump', 0); | |||
$e = error_reporting(0); | |||
trigger_error('', E_USER_DEPRECATED); | |||
@trigger_error('', E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this even here? It doesn't have a message. Presumably the intention is to pass to the $e var to trigger_error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a trick to reset the state of error_get_last() a few lines below. Silencing should be reverted here, as it's already done on line 172.
So how would I turn on deprecation notices now? |
By adding a user land error handler, like the one provided by e.g. the debug component |
eb261d4
to
00ac865
Compare
Comments addressed in code, also tests are now passing. Somehow though I seem to have broken fabbot.io. The patch just gave me this
So I applied the changes manually, but I guess maybe because I pushed another fix while fabbot.io was still running it broke it this time around. Fabbot.io was talking about code I never touched though. So I guess those problems were already there. Apparently the patch only contains garbage.... 😕 Other than that. Good to go. |
To summarize a few questions people had (that I also had): A) Do you still get deprecated warnings in the web debug toolbar? YES B) Do deprecation warnings still show up in the logs? NO Does this have any other side effects? If there are no other side effects, I'm +1. We can add something to the "how to get rid of deprecation warnings" section of the docs to show people how to hook up an error handler to log the deprecation warnings. |
Ready to be merged? |
Nice! Thanks for the clarification @nicolas-grekas. |
Would it not be better to change the production error handler instead to not log by default if that is what we want? Triggering deprecations and at the same time silence them seems like a hack. |
@Tobion this PR solves a real issue/pain users experiment with 2.7.: they must opt-out from deprecation notices. If we think this is required then we should not merge this PR. |
@reecefowell please rebase |
I agree that this should have been opt-in rather than opt-out. I do not know if there is a more elegant approach as I agree with @Tobion it seems hacky to use |
I understand how you can see this as a hack. There is an other consideration that makes me think this is really the best: performance. We could wrap the implementation of triggering "opt-in deprecation notices" behind some more semantic interface. But that would add overhead to something that needs to be as fast as possible. This is not a micro-optim when this can be called thousands of times. |
@@ -5,7 +5,7 @@ Global | |||
------ | |||
|
|||
* `E_USER_DEPRECATED` warnings - | |||
`trigger_error('... is deprecated ...', E_USER_DEPRECATED)` - | |||
`@trigger_error('... is deprecated ...', E_USER_DEPRECATED)` - | |||
are now triggered when using all deprecated functionality. | |||
To avoid filling up error logs, you may need to add |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence looks wrong now, the UPGRADE needs an update
I'm going to merge this today if nobody vote otherwise. |
👍 as I see people struggling with deprecation messages, especially in cli. However, we should provide clear instructions on how to enable them. |
👍 It also means we are much less intrusive for other libraries relying on Symfony 2.x |
👍 |
1 similar comment
👍 |
I am still not fully convinced. How would people now see the stack trace for a triggered deprecation if it is not contained in the logs? The debug toolbar doesn't provide one. |
This PR was merged into the 2.7 branch. Discussion ---------- [RFC] Fixing Deprecation Warnings This PR address an issue that causes Symfony to vomit E_DEPRECATED warnings everywhere. ```markdown | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14899 | License | MIT ``` Fixes #14899 ![http://cdn.meme.am/instances2/500x/125359.jpg](http://cdn.meme.am/instances2/500x/125359.jpg) Commits ------- 73bbaa6 Silence invasive deprecation warnings, opt-in for warnings
Thank you @reecefowell |
@xabbuh we still have to work on better deprecations reporting. |
Thanks everyone :) |
Are bundle developers encouraged to do this as well? |
@craue I'd say yes! |
👍 Good move :) |
This PR address an issue that causes Symfony to vomit E_DEPRECATED warnings everywhere.
| Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #14899 | License | MIT
Fixes #14899