Skip to content

Language: enum case identity comparison — == / === / <=> must not coerce backing scalars (Zend/zend_enum.c) #9009

Description

@PurHur

Category

language · php-src-strict

Problem

Comparing two distinct backed enum cases must use enum identity rules: == / === are false for different cases; <=> compares backing values. VM coerces cases to backing scalars and returns wrong results (E::A == E::B is true, <=> is 0).

Verified 2026-06-16: Zend PHP 8.2 vs php bin/vm.php.

php-src reference

Repro

test/repro/maintainer_gap_enum_identity_comparison.php:

<?php
enum E: int { case A = 1; case B = 2; }
var_export(E::A < E::B); echo "\n";
var_export(E::A == E::B); echo "\n";
var_export(E::A === E::B); echo "\n";
var_export(E::A <=> E::B); echo "\n";
php bin/vm.php test/repro/maintainer_gap_enum_identity_comparison.php

Zend PHP 8.2:

false
false
false
1

VM today:

true
true
true
0

Scope

Done when (php-src-strict)

  • Repro matches Zend output on VM
  • Compliance PHPT: same-case === true, different-case === false, <=> by backing
  • switch (E::A) { case E::B: ... } does not match incorrectly

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

    area: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