Question

Since I updated my project to Symfony 2.3 php notices don't throw exceptions any more.

I can try to access undefined indexes in arrays and a notice is displayed but no exception is thrown.

At first I tought I was confused and maybe this had been the behavior on prvious version. I found some question on stackoverflow that suggest otherwise.

how to handle PHP notice in symfony2

Is there anyway to make Symfony 2.3 throw exceptions on symfony2 notices?

Was it helpful?

Solution 2

I found the answer. Here it is for any reference.

https://github.com/symfony/symfony-standard/blob/master/UPGRADE-2.3.md

OTHER TIPS

Have a look at the beginning of the boot() method in the FrameworkBundle:

public function boot()
{
    ErrorHandler::register(null, false)->throwAt($this->container->getParameter('debug.error_handler.throw_at'), true);
    // ...
}

Even if you register your own error handler in AppKernel (as I was doing), the FrameworkBundle overrides it. But you can configure the FrameworkBundle's error handler using the debug.error_handler.throw_at parameter, like so:

# in config.yml, for example
parameters:
    # ALWAYS throw exceptions for notices, warnings, etc.
    debug.error_handler.throw_at: -1

I'm not aware that this is documented anywhere.

Since PHP's notices and warnings often indicate serious programming errors (d'oh!), I like to always throw exceptions for everything, even in production.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top