|
| 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. |
| 24 | + |
| 25 | +In the Symfony Framework |
| 26 | +~~~~~~~~~~~~~~~~~~~~~~~~ |
| 27 | + |
| 28 | +In the Symfony Framework, ``~E_USER_DEPRECATED`` is added to ``app/bootstrap.php.cache`` |
| 29 | +automatically, but you need at least version 2.3.14 or 3.0.21 of the |
| 30 | +`SensioDistributionBundle`_. So, you may need to upgrade: |
| 31 | + |
| 32 | +.. code-block:: bash |
| 33 | +
|
| 34 | + $ composer update sensio/distribution-bundle |
| 35 | +
|
| 36 | +Once you've updated, the ``bootstrap.php.cache`` file is rebuilt automatically. |
| 37 | +At the top, you should see a line adding ``~E_USER_DEPRECATED``. |
| 38 | + |
| 39 | +Outside of the Symfony Framework |
| 40 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 41 | + |
| 42 | +To do that, add ``~E_USER_DEPRECATED`` to your ``error_reporting`` |
| 43 | +setting in ``php.ini``: |
| 44 | + |
| 45 | +.. code-block:: ini |
| 46 | +
|
| 47 | + ; before |
| 48 | + error_reporting = E_ALL |
| 49 | + ; after |
| 50 | + error_reporting = E_ALL & ~E_USER_DEPRECATED |
| 51 | +
|
| 52 | +Alternatively, you can set this directly in bootstrap of your project:: |
| 53 | + |
| 54 | + error_reporting(error_reporting() & ~E_USER_DEPRECATED); |
| 55 | + |
| 56 | +How can I Fix the Warnings? |
| 57 | +--------------------------- |
| 58 | + |
| 59 | +Of course ultimately, you want to stop using the deprecated functionality. |
| 60 | +Sometimes, this is easy: the warning might tell you exactly what to change. |
| 61 | + |
| 62 | +But other times, the warning might be unclear: a setting somewhere might |
| 63 | +cause a class deeper to trigger the warning. In this case, Symfony does its |
| 64 | +best to give a clear message, but you may need to research that warning further. |
| 65 | + |
| 66 | +And sometimes, the warning may come from a third-party library or bundle |
| 67 | +that you're using. If that's true, there's a good chance that those deprecations |
| 68 | +have already been updated. In that case, upgrade the library to fix them. |
| 69 | + |
| 70 | +Once all the deprecation warnings are gone, you can upgrade with a lot |
| 71 | +more confidence. |
| 72 | + |
| 73 | +.. _`phpunit-bridge`: https://github.com/symfony/phpunit-bridge |
| 74 | +.. _`SensioDistributionBundle`: https://github.com/sensiolabs/SensioDistributionBundle |
0 commit comments