Category
language · php-src-strict
Problem
Backed enum cases are objects in Zend. Strict comparison with the backing scalar must be false even when the case’s value matches.
This compiler materializes E::A to backing int(1), so:
enum E: int { case A = 1; }
var_dump(E::A === 1); // Zend: false — VM today: true
var_dump(E::A == 1); // Zend: false — VM today: true
This breaks type-sensitive code, match exhaustiveness assumptions, and masks the root enum-object bug tracked under #8941 / closed #8746.
php-src reference
Repro
php bin/vm.php -r 'enum E: int { case A = 1; } var_dump(E::A === 1, E::A == 1);'
php -r 'enum E: int { case A = 1; } var_dump(E::A === 1, E::A == 1);'
| Expression |
Zend 8.4 |
VM today |
E::A === 1 |
bool(false) |
bool(true) |
E::A == 1 |
bool(false) |
bool(true) |
E::A === E::A |
bool(true) |
bool(true) |
Scope
| Layer |
Files |
| Enum fetch |
Preserve TYPE_ENUM_CASE / object handles on E::A fetch — pairs #8941 |
| Compare |
lib/VM/Variable.php equality, lib/VM/InternalCompare.php |
| JIT |
lib/JIT/JitValueCompare.php, SpaceshipCompareJit when enum operands involved |
PHP-in-PHP: no new C compare tables.
Done when
Related
Category
language· php-src-strictProblem
Backed enum cases are objects in Zend. Strict comparison with the backing scalar must be false even when the case’s value matches.
This compiler materializes
E::Ato backingint(1), so:This breaks type-sensitive code,
matchexhaustiveness assumptions, and masks the root enum-object bug tracked under #8941 / closed #8746.php-src reference
Zend/zend_enum.c— enum case asIS_OBJECT, compare hooksZend/zend_operators.c—compare_function/ strict equalityRepro
E::A === 1bool(false)bool(true)E::A == 1bool(false)bool(true)E::A === E::Abool(true)bool(true)Scope
TYPE_ENUM_CASE/ object handles onE::Afetch — pairs #8941lib/VM/Variable.phpequality,lib/VM/InternalCompare.phplib/JIT/JitValueCompare.php,SpaceshipCompareJitwhen enum operands involvedPHP-in-PHP: no new C compare tables.
Done when
false, falseon VM like ZendE::A === E::Bstill false; case singleton identity preservedtest/compliance/cases/language/enum_strict_scalar_compare.phpt./script/ci-fast.sh --filter enum_strict_scalar_comparegreenRelated
in_arraycoercion (separate but same root)