Category
language
Problem
PHP 8.0+ allows instanceof against a union of class/interface names: $obj instanceof (A|B). This compiler treats the parenthesized union as a bogus constant fetch and fails at runtime.
php-src reference
Zend/zend_compile.c — zend_compile_instanceof() / instanceof_list handling
Zend/zend_type.c — zend_type_apply_mask(), union type lists
Zend/zend_execute.c — ZEND_INSTANCEOF, instanceof_function_ex()
Repro
<?php
interface A {}
interface B {}
class C implements A, B {}
var_dump((new C) instanceof (A|B));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php # Zend: bool(true)
This compiler (May 2026): LogicException: Unknown constant fetch
Zend PHP: bool(true)
Scope (this repo)
| Layer |
Files |
| php-cfg / parser |
Union type in instanceof RHS if not already emitted |
| Compiler |
lib/Compiler.php — compileExpr for Expr_Instanceof |
| VM |
lib/VM.php — walk implemented interfaces/classes for union members |
| JIT |
lib/JIT.php — after VM PHPT green |
| Tests |
test/compliance/cases/language/instanceof_union.phpt |
Done when
Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter instanceof_union'
Related
Category
languageProblem
PHP 8.0+ allows
instanceofagainst a union of class/interface names:$obj instanceof (A|B). This compiler treats the parenthesized union as a bogus constant fetch and fails at runtime.php-src reference
Zend/zend_compile.c—zend_compile_instanceof()/instanceof_listhandlingZend/zend_type.c—zend_type_apply_mask(), union type listsZend/zend_execute.c—ZEND_INSTANCEOF,instanceof_function_ex()Repro
This compiler (May 2026):
LogicException: Unknown constant fetchZend PHP:
bool(true)Scope (this repo)
instanceofRHS if not already emittedlib/Compiler.php—compileExprforExpr_Instanceoflib/VM.php— walk implemented interfaces/classes for union memberslib/JIT.php— after VM PHPT greentest/compliance/cases/language/instanceof_union.phptDone when
bool(true)on VM;falsewhen object implements neither arm./script/ci-fast.sh --filter instanceof_uniongreendocs/capabilities-syntax.mdrow or note for unioninstanceof(regenerate matrix script)Verification
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter instanceof_union'Related
instanceofRHS)instanceofbaseline