Skip to content

Language: backed enum strict compare with backing scalar — E::A === 1 must be false (Zend/zend_enum.c) #9546

Description

@PurHur

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

  • Repro prints false, false on VM like Zend
  • E::A === E::B still false; case singleton identity preserved
  • Compliance PHPT test/compliance/cases/language/enum_strict_scalar_compare.phpt
  • ./script/ci-fast.sh --filter enum_strict_scalar_compare green

Related

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