Category
language | php-src-strict
Problem
Identity and loose equality between a backed enum case object and its backing scalar must be false in PHP 8.1+:
enum E: int { case A = 1; }
var_export(E::A == 1); // false
var_export(E::A === 1); // false
This compiler returns true for == (and historically === too). Closed #5798 fixed this; == regressed.
Root cause likely overlaps #8746 (enum cases materialized as backing scalars in some paths) — fix compare semantics regardless of storage representation.
php-src reference
Repro
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php -r "enum E: int { case A=1; } var_export(E::A==1); echo \"\n\"; var_export(E::A===1); echo \"\n\";"
php bin/vm.php -r "enum E: int { case A=1; } var_export(E::A==1); echo \"\n\"; var_export(E::A===1); echo \"\n\";"
'
| Engine |
== |
=== |
| Zend |
false |
false |
| VM today |
true ❌ |
verify (should be false) |
Also breaks switch (1) { case E::A: … } — tracked in new issue filed this run (switch scalar regression).
Scope (PHP-in-PHP)
| Piece |
Path |
| VM compare |
lib/VM/Variable.php — equals / compare for TYPE_ENUM_CASE vs int/string |
| Enum materialization |
lib/VM/EnumCaseSupport.php — ensure fetches upgrade to enum objects before compare |
| JIT/AOT |
compare lowering in lib/JIT/Builtin/Type/ |
| Tests |
test/compliance/cases/language/enum_case_not_equal_backing_scalar.phpt |
Done when
Links
#5798 (closed) · #8746 · #1492
Category
language| php-src-strictProblem
Identity and loose equality between a backed enum case object and its backing scalar must be false in PHP 8.1+:
This compiler returns
truefor==(and historically===too). Closed #5798 fixed this;==regressed.Root cause likely overlaps #8746 (enum cases materialized as backing scalars in some paths) — fix compare semantics regardless of storage representation.
php-src reference
Zend/zend_operators.c—compare_functionenum-case branchesZend/zend_enum.c—zend_compare_enum_casesRepro
=====falsefalsetrue❌false)Also breaks
switch (1) { case E::A: … }— tracked in new issue filed this run (switch scalar regression).Scope (PHP-in-PHP)
lib/VM/Variable.php—equals/compareforTYPE_ENUM_CASEvs int/stringlib/VM/EnumCaseSupport.php— ensure fetches upgrade to enum objects before comparelib/JIT/Builtin/Type/test/compliance/cases/language/enum_case_not_equal_backing_scalar.phptDone when
==and===printfalseon VME::A == "x"isfalse./script/ci-fast.sh --filter enum_case_not_equal_backinggreenLinks
#5798 (closed) · #8746 · #1492