Skip to content

Regression: duplicate backed enum values — no Error at first use (zend_enum.c, re-#5773) #8876

Description

@PurHur

Category

language — regression · php-src-strict

Problem

Two backed enum cases with the same backing value must compile in Zend; the duplicate is detected at first use (Error: Duplicate value in enum E for cases A and B). VM compiles but materializes cases as backing scalars — no duplicate error and property access on int fails silently.

Closed #5773 / #8687 tracked this; behavior regressed or was never wired on VM enum case fetch.

php-src reference

Repro

test/repro/parity_enum_duplicate_backing.php:

<?php
declare(strict_types=1);
enum E: int { case A = 1; case B = 1; }
echo E::A->name, "\n";
php test/repro/parity_enum_duplicate_backing.php
# Zend: Fatal Error: Duplicate value in enum E for cases A and B

php bin/vm.php test/repro/parity_enum_duplicate_backing.php
# VM today: Warning Attempt to read property "name" on int (E::A materialized as int)
Zend VM today
E::A->name after duplicate backing Error: Duplicate value... warning on int, no Error

Scope

  • VM enum case resolution in lib/VM/EnumCaseSupport.php (or equivalent)
  • Compiler may keep allowing duplicate declarations (Zend compiles)
  • PHP-in-PHP — no new C runtime

Done when

  • Repro throws catchable Error with duplicate message on VM
  • test/compliance/cases/language/enum_duplicate_backing.phpt green
  • JIT/AOT agree if enum case fetch is lowered

Links

#5773 · #8687 · #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

    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