On 07/10/2022 16:14, Yasuo Ohgaki wrote:
The root cause that users cannot understand what happened is this:
$ php -n -r 'set_error_handler(function ($severity,$message, $filename,
$lineno) { throw new ErrorException($message, 0, $severity, $filename,
$lineno); }); function f() { f(); } f();'
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to
allocate 262144 bytes) in Command line code on line 1
When a fatal error happens, PHP does not allow a stack dump. Very old
PHP allowed users to catch E_ERROR by user error handler, but it is
disabled to prevent users from shooting their own foot.
I suppose allowing users to catch "only one" fatal error would solve
many issues as well as infinite recursion.
Fatal errors definitely need improvements.
Stack overflows are even worth, as the process is terminated by the system:
$ php test.php
Segmentation fault
With the proposed change, an exception is throw before it happens:
$ php test.php
Fatal error: Uncaught Error: Maximum call stack size of 28672 bytes
reached. Infinite recursion? in test.php:8
Stack trace:
#0 test.php(8): C->__destruct()
#1 test.php(8): C->__destruct()
#2 test.php(8): C->__destruct()
...
#7 {main}
thrown in test.php on line 8
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php