Convert PHP Warnings and notices into fatal errors
Xdebug version 2.3 was released last week and includes a feature improvement that I requested back in 2013! Issue 1004 asked for the ability to halt on warnings and notices and I’m delighted that Derick implemented the feature and that it’s now in the general release version.
It works really simply too.
Turn on the feature by setting xdebug.halt_level either in your php.ini or via ini_set():
<?php ini_set('xdebug.halt_level', E_WARNING|E_NOTICE|E_USER_WARNING|E_USER_NOTICE);
Now cause a warning:
<?php echo "Before"; imagecreatefromstring(null); // Don't pass null into imagecreatefromstring()! echo "After";
The result is that “Before” is displayed and then we get the standard Xdebug notice, but “After” is not displayed as the script is halted on the due to the warning.
I used to have a error handler in place solely to do this, but now I don’t need it!
The most common use-case I have for it is a warning that occurs during a POSTed request that redirects to another page. Other people are dedicated log-checkers, but I’m not and vastly prefer seeing the big orange box telling what’s gone wrong.
As I said, I’m really happy to see this feature; it’s worth considering turning on your development set up too!
2 thoughts on “Convert PHP Warnings and notices into fatal errors”
Comments are closed.