[php-src] Issue #8033: Unexpected stop of the script after an exception breaking the expected workflow

From: Date: Fri, 04 Feb 2022 10:31:25 +0000
Subject: [php-src] Issue #8033: Unexpected stop of the script after an exception breaking the expected workflow
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-239475@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/8033 Author: josepsanzcamp ### Description Hi, I don't know if this can be considered an error or a feature, depending of the view point, but I have detected that some of my code have a different workflow from php >= 8.0. The following code: ```php <?php // phpcs:disable PSR1.Files.SideEffects function __error_handler($type, $message, $file, $line) { print_r(array( "function" => __FUNCTION__, "phperror" => "${message} (code ${type})", "details" => "Error on file " . basename($file) . ":" . $line, //~ "backtrace" => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) )); } function __exception_handler($e) { print_r(array( "function" => __FUNCTION__, "exception" => $e->getMessage() . " (code " . $e->getCode() . ")", "details" => "Error on file " . basename($e->getFile()) . ":" . $e->getLine(), //~ "backtrace" => $e->getTrace() )); } function __shutdown_handler() { $error = error_get_last(); $types = array(E_ERROR,E_PARSE,E_CORE_ERROR,E_COMPILE_ERROR,E_USER_ERROR,E_RECOVERABLE_ERROR); if (is_array($error) && isset($error["type"]) && in_array($error["type"], $types)) { print_r(array( "function" => __FUNCTION__, "phperror" => "${error["message"]}", "details" => "Error on file " . basename($error["file"]) . ":" . $error["line"], //~ "backtrace" => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) )); } else { print_r(array( "function" => __FUNCTION__, //~ "backtrace" => debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS) )); } } error_reporting(E_ALL); set_error_handler("__error_handler"); set_exception_handler("__exception_handler"); register_shutdown_function("__shutdown_handler"); $a = array(1,2,3); $b = array(1,2); $c = array_combine($a, $b); echo "OK OK OK!!!\n"; die(); ``` Resulted in this output in php >= 8.0: ``` Array ( [function] => __exception_handler [exception] => array_combine(): Argument #1 ($keys) and argument #2 ($values) must have the same number of elements (code 0) [details] => Error on file error.php:51 ) Array ( [function] => __shutdown_handler ) ``` But I expected this output instead as in php <= 7.4: ``` Array ( [function] => __error_handler [phperror] => array_combine(): Both parameters should have an equal number of elements (code 2) [details] => Error on file error.php:51 ) OK OK OK!!! Array ( [function] => __shutdown_handler ) ``` The main problem is that the code stops after the exception and the OK OK OK!!! not appear. I understand that the correct is use the try catch to control this exception, but to do compatible with a lot of existing code, is there some method to allow the runtime machine to continue executing the code after the exception at the next point as in php7.4??? Note: I have used the 7.4.27 and 8.0.15 php versions to do the tests Thanks in advance. Josep. ### PHP Version PHP version 8.0.15 ### Operating System Debian GNU/Linux 11.2 (bullseye)

« previous php.bugs (#239475) next »