php-src/Zend/tests/gh13446_2.phpt
Ilija Tovilo 3301d9602a
Restore error handler after running it
Symfony relies on finding the exception handler in the handler stack. There's
currently no clean API to find it, so they pop all the handlers, and push them
again once the stack is empty. This PR attempts to minimize the BC break by
pushing the current handler onto the stack and clearing the current handler, and
restoring it once it has finished. This is essentially equivalent to
set_exception_handler(null) and restore_exception_handler().

restore_exception_handler() however is only called if the exception handler is
still unset. If the handler has pushed a new handler in the meantime, we assume
it knows what it's doing.

Fixes GH-13446
Closes GH-13686
2024-03-20 10:53:20 +01:00

17 lines
309 B
PHP

--TEST--
GH-13446: Exception handler attempting to free itself
--FILE--
<?php
$x = new \stdClass();
$handler = function ($ex) use (&$handler, $x) {
$handler = null;
var_dump($x);
};
unset($x);
set_exception_handler($handler);
throw new Exception('Unhandled');
?>
--EXPECT--
object(stdClass)#1 (0) {
}