Skip to content

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

Description

@PurHur

Category

language · php-src-strict

Problem

Closed #9193 added duplicate backing-value detection, but VM regressed: accessing E::A on an enum with duplicate backing values emits property-read warnings on int instead of Zend's first-use Error: Duplicate value in enum E for cases A and B.

Compliance guard test/compliance/cases/language/enum_duplicate_backing_value.phpt is red (verified 2026-06-18).

php-src reference

Repro

<?php
enum E: int {
    case A = 1;
    case B = 1;
}

try {
    echo E::A->name, "\n";
} catch (Throwable $e) {
    echo get_class($e), ': ', $e->getMessage(), "\n";
}

enum F: int { case A = 1; case B = 2; }
echo F::A->name, "\n";

Save as test/repro/maintainer_enum_duplicate_backing.php.

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_enum_duplicate_backing.php
php bin/vm.php test/repro/maintainer_enum_duplicate_backing.php
'
Runtime First block Second enum
Zend Error: Duplicate value in enum E for cases A and B A
VM today Warning: Attempt to read property "name" on int may also warn

Root cause overlaps #9676 (enum cases scalarized) — fix duplicate check on enum case objects, not ints.

Scope (this repo)

Layer Path
VM lib/VM/BackedEnum.php — duplicate map at first case materialization
Compiler enum case table build — optional compile-time duplicate detect
Tests test/compliance/cases/language/enum_duplicate_backing_value.phpt

Done when

  • Repro first try prints exact Zend Error: message (class + text)
  • Valid enum F::A still prints A
  • No E_WARNING property-read noise before the Error
  • ./script/ci-fast.sh --filter enum_duplicate_backing green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter enum_duplicate_backing'

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

    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