Skip to content

Regression: duplicate backed enum values — first-use Error still missing (Zend/zend_enum.c, re-#8876) #9193

Description

@PurHur

Category

language — regression · php-src-strict

Problem

Two backed enum cases with the same backing value must compile in Zend; duplicate detection runs at first use of any case:

enum E: int { case A = 1; case B = 1; }
E::A->name; // Error: Duplicate value in enum E for cases A and B

Issues #8687 / #8876 were closed, but VM still materializes cases as backing scalars — no duplicate Error and property access on int fails with a warning instead.

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro-maintainer/parity_duplicate_enum_backing_value.php
php bin/vm.php test/repro-maintainer/parity_duplicate_enum_backing_value.php
'
Runtime E::A->name
Zend Error: Duplicate value in enum E for cases A and B
VM Warning: Attempt to read property "name" on int (no Error)

Scope

Layer Files
VM lib/VM/EnumSupport.php — enforce duplicate map on first case materialization
Compile optional early fatal if both cases are constant-foldable (Zend allows compile)
Tests test/compliance/cases/language/enum_duplicate_backing_value.phpt

PHP-in-PHP: duplicate tracking belongs in lib/VM/EnumSupport.php; do not add C runtime branches.

Done when

  • Repro throws Error with Zend message on VM (JIT/AOT same script)
  • Non-duplicate backed enums unaffected
  • ./script/ci-fast.sh --filter enum_duplicate_backing 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 machineimplementation-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