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

[RFC] Fixing Deprecation Warnings #14900

Merged
merged 1 commit into from Jun 10, 2015
Merged

Conversation

reecefowell
Copy link
Contributor

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

http://cdn.meme.am/instances2/500x/125359.jpg

@perk11
Copy link

perk11 commented Jun 7, 2015

👍 had numerous deprecated warnings after upgrading to 2.7 and this PR solved all of them.

@xabbuh
Copy link
Member

xabbuh commented Jun 7, 2015

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 error_reporting level, but I'd rather update your code.

@xabbuh xabbuh closed this Jun 7, 2015
@nicolas-grekas
Copy link
Member

This PR may be a good idea in fact don't you think?

@elnur
Copy link
Contributor

elnur commented Jun 7, 2015

The most profound PR I've ever seen. A must merge. 👍

@xabbuh
Copy link
Member

xabbuh commented Jun 7, 2015

@nicolas-grekas Not sure if I understand. Which issue would this change actually solve?

@nicolas-grekas
Copy link
Member

It switches deprecation notices from opt-out to opt-in

@xabbuh
Copy link
Member

xabbuh commented Jun 7, 2015

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.

@reecefowell
Copy link
Contributor Author

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).

@nicolas-grekas
Copy link
Member

Still thinking about it, I really like the idea.
Upgrading to 3.0 is also an opt in, the upgrade path is clear.

I'm 👍
Reopening to see what other @symfony/deciders think

@nicolas-grekas nicolas-grekas reopened this Jun 7, 2015
@nicolas-grekas
Copy link
Member

@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);
Copy link
Member

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

@stof
Copy link
Member

stof commented Jun 7, 2015

@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 ?

@nicolas-grekas
Copy link
Member

nicolas-grekas commented Jun 7, 2015 via email

@fabpot
Copy link
Member

fabpot commented Jun 7, 2015

ping @symfony/deciders

If we agree on this one, I'd like to merge ASAP for at least two reasons:

  • I want to release 2.7.1 ASAP
  • Maintaining such a large patch is going to be difficult over time.

@Tobion
Copy link
Member

Tobion commented Jun 7, 2015

So this only changes that the deprecation warnings are ignored in production, or?

@nicolas-grekas
Copy link
Member

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);
Copy link
Contributor Author

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?

Copy link
Member

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.

@linaori
Copy link
Contributor

linaori commented Jun 8, 2015

So how would I turn on deprecation notices now?

@nicolas-grekas
Copy link
Member

By adding a user land error handler, like the one provided by e.g. the debug component

@reecefowell
Copy link
Contributor Author

Comments addressed in code, also tests are now passing. Somehow though I seem to have broken fabbot.io.

The patch just gave me this

curl http://fabbot.io/patch/symfony/symfony/14900/eb261d45b038f9af47a92b4e6b602bcf8a853816/cs.diff | patch -p0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  8717  100  8717    0     0  20591      0 --:--:-- --:--:-- --:--:-- 20607
patch: **** Only garbage was found in the patch input.

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.

@weaverryan
Copy link
Member

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.

@fabpot
Copy link
Member

fabpot commented Jun 9, 2015

Ready to be merged?

@phansys
Copy link
Contributor

phansys commented Jun 9, 2015

Nice! Thanks for the clarification @nicolas-grekas.

@Tobion
Copy link
Member

Tobion commented Jun 9, 2015

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.

@nicolas-grekas
Copy link
Member

@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.
If we think the deprecations should be opt-in, as would be migrating 3.0, then this PR is the right one.
Nobody but me voted here. Please do @symfony/deciders

@nicolas-grekas
Copy link
Member

@reecefowell please rebase

@lsmith77
Copy link
Contributor

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 @trigger_error().

@nicolas-grekas
Copy link
Member

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.
Thus this raw-bare-metal-php implementation that may look hacky, but is just the right implementation for our needs. At least that's my humble opinion :)

@@ -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
Copy link
Member

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

@fabpot
Copy link
Member

fabpot commented Jun 10, 2015

I'm going to merge this today if nobody vote otherwise.

@jakzal
Copy link
Contributor

jakzal commented Jun 10, 2015

👍 as I see people struggling with deprecation messages, especially in cli. However, we should provide clear instructions on how to enable them.

@stof
Copy link
Member

stof commented Jun 10, 2015

👍

It also means we are much less intrusive for other libraries relying on Symfony 2.x

@matthias-chlechowitz
Copy link

👍

1 similar comment
@aitboudad
Copy link
Contributor

👍

@xabbuh
Copy link
Member

xabbuh commented Jun 10, 2015

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.

@nicolas-grekas nicolas-grekas merged commit 73bbaa6 into symfony:2.7 Jun 10, 2015
nicolas-grekas added a commit that referenced this pull request Jun 10, 2015
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
@nicolas-grekas
Copy link
Member

Thank you @reecefowell

@nicolas-grekas
Copy link
Member

@xabbuh we still have to work on better deprecations reporting.
But at least, we can do it quietly now, without hurting users.

@reecefowell
Copy link
Contributor Author

Thanks everyone :)

@craue
Copy link
Contributor

craue commented Jun 10, 2015

Are bundle developers encouraged to do this as well?

@nicolas-grekas
Copy link
Member

@craue I'd say yes!

@reecefowell reecefowell deleted the 2.7 branch June 10, 2015 16:46
@mmoreram
Copy link
Contributor

👍 Good move :)

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

Successfully merging this pull request may close these issues.

None yet