Skip to content

Stdlib: Exception::getPrevious() / Throwable chain — missing VM method (zend_exceptions.c) #5104

Description

@PurHur

Category

stdlib | implementation-ready (partial — see status)

Status (2026-06-06 audit)

Method VM Notes
getPrevious() green lib/VM/Builtin/ExceptionGetPrevious.php — three-arg ctor chain works
getTrace() missing tracked in #7159
getTraceAsString() missing tracked in #7159
__toString() missing echo $e fatals — #7159

Keep this issue for constructor $previous wiring + regression tests; implement remaining Throwable surface in #7159.

Problem

Exception / Throwable instances need full Zend exception chain semantics. getPrevious() now works, but trace accessors and string casting remain broken, blocking real error handlers and echo $exception formatting.

php-src reference

  • php/php-src Zend/zend_exceptions.c — zend_exception_get_previous(), zend_exception_get_trace(), zend_std_cast_object_tostring
  • Constructor $previous argument wiring in zend_exception_ctor()

Repro — getPrevious (green)

test/repro-maintainer/exception_get_previous.php:

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/exception_get_previous.php
php bin/vm.php test/repro-maintainer/exception_get_previous.php'
Check Zend VM
getPrevious() instanceof Exception true true
getPrevious()->getMessage() 'inner' 'inner'

Repro — remaining gaps (see #7159)

<?php
$e = new Exception('outer', 0, new Exception('inner'));
echo $e, "\n"; // Zend: chained text; VM: fatal

Scope

Path Work
lib/VM/Builtin/ExceptionGetPrevious.php done
lib/VM/Builtin/ExceptionConstruct.php ensure 3rd $previous stored on all Throwable types
lib/Compiler.php pass previous into throw / new Exception with 3rd arg
#7159 getTrace, getTraceAsString, __toString

Done when

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./vendor/bin/phpunit --filter exception_get_previous'

Links

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions