How can I terminate / halt a PHP script and return an error exit code if ANY errors occur?
Basically the functionality that is provided by set -e
in Bash?
I’ve tried setting ini_set('error_reporting', E_ALL);
but this does not actually halt the script when an error occurs.
Advertisement
Answer
This seems to do the job:
set_error_handler(function ($errno, $errstr, $errfile, $errline) { throw new ErrorException($errstr, $errno, 0, $errfile, $errline); });