Category
language · php-src-strict · Exception $previous typing
Problem
Passing a non-Throwable object as Exception/Error $previous must raise TypeError with Zend’s argument message. php-compiler throws host LogicException (Exception previous must implement Throwable / must be an object) from ExceptionSupport::setExceptionPrevious.
Probed 2026-08-07 vs host Zend 8.2.32 (VM).
| Repro |
Zend |
VM |
throw new Exception("m", 0, new stdClass); |
TypeError: Exception::__construct(): Argument #3 ($previous) must be of type ?Throwable, stdClass given |
LogicException: Exception previous must implement Throwable |
valid ?Throwable previous |
chains via getPrevious() |
OK |
php-src reference
PHP implementation target
lib/VM/ExceptionSupport.php — setExceptionPrevious: emit userland TypeError with Zend wire message (reuse shared arg TypeError helpers), not host LogicException
- Same path for ErrorException sixth arg / Error construct
Repro
./script/docker-exec.sh -- bash -lc 'cat > /tmp/ex_prev.php <<'"'"'PHP'"'"'
<?php
try {
throw new Exception("m", 0, new stdClass);
} catch (Throwable $e) {
echo get_class($e), "|", $e->getMessage(), "\n";
}
PHP
php /tmp/ex_prev.php
php bin/vm.php /tmp/ex_prev.php'
Done when
Category
language· php-src-strict · Exception$previoustypingProblem
Passing a non-
Throwableobject as Exception/Error$previousmust raiseTypeErrorwith Zend’s argument message. php-compiler throws hostLogicException(Exception previous must implement Throwable/must be an object) fromExceptionSupport::setExceptionPrevious.Probed 2026-08-07 vs host Zend 8.2.32 (VM).
throw new Exception("m", 0, new stdClass);TypeError:Exception::__construct(): Argument #3 ($previous) must be of type ?Throwable, stdClass givenLogicException:Exception previous must implement Throwable?ThrowablepreviousgetPrevious()php-src reference
Zend/zend_exceptions.c—zend_parse_parameters(..., "|SlO!", ..., &previous, zend_ce_throwable)(O!→ TypeError on wrong class)Zend/zend_exceptions.stub.php—?Throwable $previous = nullPHP implementation target
lib/VM/ExceptionSupport.php—setExceptionPrevious: emit userlandTypeErrorwith Zend wire message (reuse shared arg TypeError helpers), not hostLogicExceptionRepro
Done when
$previous→TypeErrorwith Zend message text (VM + JIT).phptundertest/compliance/cases/language/