Skip to content

Language: Exception::__construct($previous) throws LogicException — Zend TypeError (Zend/zend_exceptions.c) #28798

Description

@PurHur

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.phpsetExceptionPrevious: 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

  • Non-Throwable $previousTypeError with Zend message text (VM + JIT)
  • Valid Throwable previous still chains
  • Compliance .phpt under test/compliance/cases/language/
  • php-src-strict; no php-compiler-strict shortcut

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 machinebugSomething isn't workingimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions