Category
language | php-src-strict
Problem
The instanceof operator on enum case operands returns false for UnitEnum and BackedEnum on VM/JIT. Zend treats backed/unit enum cases as objects implementing those interfaces, so instanceof is true.
This is distinct from #9152 (is_a/is_subclass_of function parity) — the opcode path in lib/VM.php / lib/JIT/ must tag enum-case Variable operands with enum interfaces before interface checks.
php-src reference
Repro
<?php
enum E: int { case A = 1; }
var_dump(E::A instanceof UnitEnum);
var_dump(E::A instanceof BackedEnum);
var_dump(E::A instanceof E);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
| Check |
Zend PHP 8.x |
This compiler (bin/vm.php) |
E::A instanceof UnitEnum |
true |
false |
E::A instanceof BackedEnum |
true |
false |
E::A instanceof E |
true |
(verify; may also be wrong if case is scalarized) |
Scope
| Module |
Path |
| VM compare / instanceof |
lib/VM.php, lib/VM/Variable.php — preserve TYPE_ENUM_CASE through operand resolution |
| JIT instanceof |
lib/JIT/IssetHelper.php / instanceof lowering helpers — enum-case interface bitmap |
| Tests |
test/compliance/cases/language/enum_instanceof_unitenum.phpt (VM + JIT) |
PHP-in-PHP: no new runtime/*.c — enum case representation stays in lib/VM/EnumCaseSupport.php.
Done when
Related
Category
language| php-src-strictProblem
The
instanceofoperator on enum case operands returnsfalseforUnitEnumandBackedEnumon VM/JIT. Zend treats backed/unit enum cases as objects implementing those interfaces, soinstanceofis true.This is distinct from #9152 (
is_a/is_subclass_offunction parity) — the opcode path inlib/VM.php/lib/JIT/must tag enum-caseVariableoperands with enum interfaces before interface checks.php-src reference
Zend/zend_operators.c—instance_of_function, enumzend_is_enumbranchesZend/zend_enum.c— enum case object handlers,UnitEnum/BackedEnuminterface listZend/zend_interfaces.h—instanceof_function_slowRepro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php' php repro.phpbin/vm.php)E::A instanceof UnitEnumtruefalseE::A instanceof BackedEnumtruefalseE::A instanceof EtrueScope
lib/VM.php,lib/VM/Variable.php— preserveTYPE_ENUM_CASEthrough operand resolutionlib/JIT/IssetHelper.php/ instanceof lowering helpers — enum-case interface bitmaptest/compliance/cases/language/enum_instanceof_unitenum.phpt(VM + JIT)PHP-in-PHP: no new
runtime/*.c— enum case representation stays inlib/VM/EnumCaseSupport.php.Done when
bin/vm.php)--filter enum_instanceof/ matching JIT PHPT is in scope./script/ci-fast.sh --filter enum_instanceofgreeninstanceofchecksRelated
is_a/is_subclass_of· Stdlib: get_debug_type() on enum cases — must return enum name not scalar (ext/standard/type.c, #3454) #5509get_debug_type· Regression: gettype() on backed enum cases returns integer not object (re-#5496, basic_functions.c) #8810gettype· Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492 self-host