Search code examples
phpsymfonysymfony-2.7

Disable deprecated warning in Symfony 2(.7)


Since my Symfony 2 update to 2.7. I get a lot of deprecated erors in PHPUnit and console (message is clear by now).

ProjectX\ApiBundle\Tests\Controller\SectionsControllerTest::testPostDebug()
The twig.form.resources configuration key is deprecated since version 2.6 and will be removed in 3.0. Use the twig.form_themes configuration key instead.

Any idea how to disable them for now?


Solution

  • I have the same problem and solved it similar to the below link. Symfony declares to report all errors and overrides what you put in php.ini by design (otherwise it couldn't catch & display nice stack traces for you).

    So, you'll need to override Symfony2's built-in error reporting by creating an init() function in your AppKernel.php and setting the error_reporting how you'd like there, along with (probably) some environment detection to make sure you don't display errors in production, for example:

    // Add this to app/AppKernel.php
    public function init()
    {
        if ($this->debug) {
            ini_set('display_errors', 1);
            error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED);
        } else {
            ini_set('display_errors', 0);
        }
    }
    

    More details here (use Google Translate if you do not read Russian :) http://tokarchuk.ru/2012/12/disable-deprecated-warnings-in-symfony-2/