|
| 1 | +What do these "XXX is deprecated " E_USER_DEPRECATED Warnings mean? |
| 2 | +=================================================================== |
| 3 | + |
| 4 | +Starting in Symfony 2.7, if you use a deprecated class, function or option, |
| 5 | +Symfony triggers an ``E_USER_DEPRECATED`` error. Internally, that looks something |
| 6 | +like this:: |
| 7 | + |
| 8 | + trigger_error( |
| 9 | + 'The fooABC method is deprecated since version 2.4 and will be removed in 3.0.', |
| 10 | + E_USER_DEPRECATED |
| 11 | + ); |
| 12 | + |
| 13 | +This is great, because you can check your logs to know what needs to change |
| 14 | +before you upgrade. In the Symfony Framework, the number of deprecated calls |
| 15 | +shows up in the web debug toolbar. And if you install the `phpunit-bridge`_, |
| 16 | +you can get a report of deprecated calls after running your tests. |
| 17 | + |
| 18 | +How can I Silence the Warnings? |
| 19 | +------------------------------- |
| 20 | + |
| 21 | +As useful as these are, you don't want them to show up while developing and |
| 22 | +you may also want to silence them on production to avoid filling up your |
| 23 | +error logs. To do that, add ``~E_USER_DEPRECATED`` to your ``error_reporting`` |
| 24 | +setting in ``php.ini``: |
| 25 | + |
| 26 | +.. code-block:: ini |
| 27 | +
|
| 28 | + ; before |
| 29 | + error_reporting = E_ALL |
| 30 | + ; after |
| 31 | + error_reporting = E_ALL & ~E_USER_DEPRECATED |
| 32 | +
|
| 33 | +Alternatively, you can set this directly in bootstrap of your project:: |
| 34 | + |
| 35 | + error_reporting(error_reporting() & ~E_USER_DEPRECATED); |
| 36 | + |
| 37 | +How can I Fix the Warnings? |
| 38 | +--------------------------- |
| 39 | + |
| 40 | +Of course ultimately, you want to stop using the deprecated functionality. |
| 41 | +Sometimes, this is easy: the warning might tell you exactly what to change. |
| 42 | + |
| 43 | +But other times, the warning might be un-clear: a setting somewhere might |
| 44 | +cause a class deeper to trigger the warning. In this case, the core team |
| 45 | +does its best to give a clear message, but you may need to research that |
| 46 | +warning further. |
| 47 | + |
| 48 | +And sometimes, the warning may come from a third-party library or bundle |
| 49 | +that you're using. If that's true, there's a good chance that those deprecations |
| 50 | +have already been updated. In that case, upgrade the library to fix them. |
| 51 | + |
| 52 | +Once all the deprecation warnings are gone, you can upgrade without a lot |
| 53 | +more confidence. |
| 54 | + |
| 55 | +.. _`phpunit-bridge`: https://github.com/symfony/phpunit-bridge |
| 56 | + |
0 commit comments