Skip to content

Regression: backed enum case loose == with backing scalar returns true (re-#5798, zend_operators.c) #8766

Description

@PurHur

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.phpequals / 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

  • Repro: both == and === print false on VM
  • String-backed enum: E::A == "x" is false
  • JIT/AOT agree when compare is lowered
  • ./script/ci-fast.sh --filter enum_case_not_equal_backing green

Links

#5798 (closed) · #8746 · #1492

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

    IMPORTANTCritical patharea:vmVirtual machineenhancementNew feature or requestimplementation-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