Category
stdlib | runtime
Problem
Builtin Throwable / Exception / Error objects are missing core introspection methods that Zend exposes on every thrown object:
| Method |
Zend PHP 8.x |
This compiler VM (2026-06-06) |
getTrace() |
true (method_exists) |
false |
getTraceAsString() |
true |
false |
__toString() |
echo $e prints message + stack |
Error: Object of class Exception could not be converted to string |
ExceptionTrace::captureOnThrow() already stores a trace property on throw (#3351), but there is no public getTrace() accessor. getPrevious() landed in lib/VM/Builtin/ExceptionGetPrevious.php (#5104 partial) — this issue covers the remaining Throwable surface.
Nested exception string formatting (Next Exception: chain) also depends on __toString() + getPrevious() working together.
php-src reference
Repro
Save as test/repro-maintainer/throwable_introspection.php:
<?php
declare(strict_types=1);
$inner = new Exception('inner');
$outer = new Exception('outer', 0, $inner);
echo 'getTrace ', method_exists($outer, 'getTrace') ? 'yes' : 'no', "\n";
echo 'getTraceAsString ', method_exists($outer, 'getTraceAsString') ? 'yes' : 'no', "\n";
try {
throw new Exception('x');
} catch (Exception $e) {
echo 'trace_is_array ', is_array($e->getTrace()) ? 'yes' : 'no', "\n";
echo 'trace_str ', substr($e->getTraceAsString(), 0, 9), "\n";
}
echo $outer, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/throwable_introspection.php
php bin/vm.php test/repro-maintainer/throwable_introspection.php'
| Check |
Zend |
VM today |
method_exists(..., 'getTrace') |
yes |
no |
getTrace() after catch |
array |
undefined method |
getTraceAsString() prefix |
#0 |
undefined method |
echo $outer |
chained text with Next Exception |
fatal: could not be converted to string |
Scope (this repo)
| Path |
Work |
lib/VM/Builtin/ExceptionGetTrace.php |
new — return captured trace property array |
lib/VM/Builtin/ExceptionGetTraceAsString.php |
new — format like debug_backtrace() string renderer |
lib/VM/Builtin/ExceptionToString.php |
new — __toString with previous-chain formatting |
lib/VM/BuiltinClasses.php / ext/standard/ThrowableManifest.php |
register methods on Throwable hierarchy |
lib/VM/ExceptionTrace.php |
ensure trace populated for Error subclasses too |
| JIT/AOT |
VM fallback acceptable v1; note in capabilities if deferred |
| Tests |
test/compliance/cases/stdlib/throwable_get_trace.phpt, throwable_to_string_chain.phpt |
PHP-in-PHP: implement in lib/VM/Builtin/* + manifest; do not add new C in lib/AOT/runtime/.
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter throwable_get_trace'
Category
stdlib|runtimeProblem
Builtin
Throwable/Exception/Errorobjects are missing core introspection methods that Zend exposes on every thrown object:getTrace()true(method_exists)falsegetTraceAsString()truefalse__toString()echo $eprints message + stackError: Object of class Exception could not be converted to stringExceptionTrace::captureOnThrow()already stores atraceproperty on throw (#3351), but there is no publicgetTrace()accessor.getPrevious()landed inlib/VM/Builtin/ExceptionGetPrevious.php(#5104 partial) — this issue covers the remaining Throwable surface.Nested exception string formatting (
Next Exception:chain) also depends on__toString()+getPrevious()working together.php-src reference
Zend/zend_exceptions.c—zend_exception_get_trace(),zend_exception_get_trace_as_string(),zend_exception_object_get_properties(),zend_std_cast_object_tostringZend/zend_exceptions.stub.php—Throwablemethod tableRepro
Save as
test/repro-maintainer/throwable_introspection.php:method_exists(..., 'getTrace')yesnogetTrace()after catchgetTraceAsString()prefix#0echo $outerNext ExceptionScope (this repo)
lib/VM/Builtin/ExceptionGetTrace.phptraceproperty arraylib/VM/Builtin/ExceptionGetTraceAsString.phpdebug_backtrace()string rendererlib/VM/Builtin/ExceptionToString.php__toStringwith previous-chain formattinglib/VM/BuiltinClasses.php/ext/standard/ThrowableManifest.phpThrowablehierarchylib/VM/ExceptionTrace.phpErrorsubclasses tootest/compliance/cases/stdlib/throwable_get_trace.phpt,throwable_to_string_chain.phptPHP-in-PHP: implement in
lib/VM/Builtin/*+ manifest; do not add new C inlib/AOT/runtime/.Done when
bin/vm.phpTypeError/Errorsubclasses expose the same methods (not onlyException)./script/ci-fast.sh --filter throwable_get_tracegreenVerification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter throwable_get_trace'