Category
stdlib / runtime
Problem
set_exception_handler() and restore_exception_handler() are not registered. Uncaught exceptions always reach the VM top-level handler; Zend allows a user callback (and a stack of previous handlers) before process exit.
Blocked by: builtin Exception / Throwable classes (#195) — handler receives Throwable objects.
php-src reference
ext/standard/basic_functions.c — PHP_FUNCTION(set_exception_handler), restore_exception_handler
Zend/zend_exceptions.c — zend_exception_get_default(), uncaught handler chain, zend_throw_exception_hook
Repro (today)
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "var_dump(function_exists(\"set_exception_handler\"));"'
# bool(false)
<?php
set_exception_handler(function (Throwable $e): void {
echo 'handled:', $e->getMessage(), "\n";
});
throw new Exception('x');
Zend PHP: handled:x (no fatal). This compiler: undefined function and/or non-existing class Exception.
Stack behavior (done-when detail)
set_exception_handler(fn() => print "a\n");
set_exception_handler(fn() => print "b\n");
restore_exception_handler();
throw new Exception('z');
// Zend: prints b, then on second restore a, then default handler
Scope (this repo)
| Piece |
Path |
| Builtin |
ext/standard/set_exception_handler.php, restore_exception_handler.php |
| Registry |
ext/standard/Module.php |
| VM |
lib/VM/Context.php — handler stack; lib/VM.php uncaught path calls top handler |
| Prerequisite |
#195 — register Exception, Throwable, Error |
| Web |
lib/Web/ — optional: map uncaught to HTTP 500 after handler (#152) |
| Tests |
test/compliance/cases/stdlib/exception_handler.phpt |
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter exception_handler'
Related
Labels
stdlib, implementation-ready, phase-4:stdlib, area:vm
Category
stdlib/runtimeProblem
set_exception_handler()andrestore_exception_handler()are not registered. Uncaught exceptions always reach the VM top-level handler; Zend allows a user callback (and a stack of previous handlers) before process exit.Blocked by: builtin
Exception/Throwableclasses (#195) — handler receivesThrowableobjects.php-src reference
ext/standard/basic_functions.c—PHP_FUNCTION(set_exception_handler),restore_exception_handlerZend/zend_exceptions.c—zend_exception_get_default(), uncaught handler chain,zend_throw_exception_hookRepro (today)
Zend PHP:
handled:x(no fatal). This compiler: undefined function and/or non-existing classException.Stack behavior (done-when detail)
Scope (this repo)
ext/standard/set_exception_handler.php,restore_exception_handler.phpext/standard/Module.phplib/VM/Context.php— handler stack;lib/VM.phpuncaught path calls top handlerException,Throwable,Errorlib/Web/— optional: map uncaught to HTTP 500 after handler (#152)test/compliance/cases/stdlib/exception_handler.phptDone when
handled:xon VM without process fatalrestore_exception_handler()restores previous callback; nestedset_*matches Zend orderfalsefalls through to previous/default (Zend)./script/ci-fast.sh --filter exception_handlergreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter exception_handler'Related
error_log· Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492 self-host exception pathsLabels
stdlib,implementation-ready,phase-4:stdlib,area:vm