[php-src] Issue #10349: Non-Catchable, Non-Fatal Exception in PHP 8.0+

From: Date: Mon, 16 Jan 2023 19:26:59 +0000
Subject: [php-src] Issue #10349: Non-Catchable, Non-Fatal Exception in PHP 8.0+
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-243468@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/10349 Author: hakre ### Description The following code: ```php <?php declare(strict_types=1); /* * PHP 8.0+ throw exception in error handler while proc_open executable not in path warning exit code 127 (shell/system) */ error_reporting(~0); function error_handler($code, $message, $file, $line) { fprintf(STDOUT, "error: %s ** and throw **\n", var_export(array_slice(func_get_args(), 0, 4), true)); throw new ErrorException($message, 0, $code, $file, $line); // non-catchable non-fatal exception } set_error_handler('error_handler', ~0); $pipes = []; // command must be passed as array to trigger this, string won't work. $process = proc_open(['non-existent-command'], [], $pipes); // directly produce some output fprintf(STDOUT, "open: %d\n", $process); $status = proc_get_status($process); ksort($status); fprintf(STDOUT, "status: %s\n", json_encode($status)); // let proc finish usleep(100000); $status = proc_get_status($process); ksort($status); fprintf(STDOUT, "status: %s\n", json_encode($status)); $close = proc_close($process); fprintf(STDOUT, "close: %s\n", var_export($close, true)); ``` Resulted in this output: ``` open: 4 status: {"command":"non-existent-command","exitcode":-1,"pid":768535,"running":true,"signaled":false,"stopped":false,"stopsig":0,"termsig":0} error: array ( 0 => 2, 1 => 'proc_open(): Exec failed: No such file or directory', 2 => '/home/mot/PhpstormProjects/make-and-compose/.cache/plain/scripts/procOpenThrow.php', 3 => 17, ) ** and throw ** status: {"command":"non-existent-command","exitcode":127,"pid":768535,"running":false,"signaled":false,"stopped":false,"stopsig":0,"termsig":0} close: -1 ``` (exit status 0) But I expected this output instead: ``` open: 4 status: {"command":"non-existent-command","exitcode":-1,"pid":768535,"running":true,"signaled":false,"stopped":false,"stopsig":0,"termsig":0} PHP Fatal error: Uncaught ErrorException: proc_open(): Exec failed: No such file or directory in script.php:17 Stack trace: #0 {main} thrown in script.php on line 17 ``` (exit status 255) ### PHP Version PHP 8.0.27 (cli) (built: Jan 13 2023 10:42:52) ( NTS ) ### Operating System Ubuntu 20.04

« previous php.bugs (#243468) next »