Skip to content

Language: enum class/trait/interface constants — E::X must resolve (zend_enum.c, zend_constants.c) #6407

Description

@PurHur

Category

language

Problem

Enum types cannot resolve class constants declared on the enum itself or inherited via traits/interfaces. E::X throws Error: Undefined class constant E::X in the VM; Zend returns the constant value.

Related stdlib gaps (#5682, #3484) cover constant('E::A') for enum cases, not public const / trait const on enum types.

php-src-strict: direct E::X, constant('E::X'), and trait-merged constants must match Zend.

php-src reference

Repro (failure today)

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_enum_class_constant.php   # Error: Undefined class constant E::X
php bin/vm.php test/repro/parity_enum_trait_const.php          # trait const on enum — same failure
php test/repro/maintainer_enum_class_constant.php              # Zend: 42
php test/repro/parity_enum_trait_const.php                     # Zend: 1
'
<?php
// enum-declared constant
enum E { case A; public const X = 42; }
echo E::X; // VM: Error; Zend: 42

// trait constant on enum
trait T { public const X = 1; }
enum E { use T; }
echo E::X; // VM: Error; Zend: 1

Implementation hints (PHP-in-PHP)

  • Register enum constants in compiler symbol tables (lib/ lowering), not new C branches in runtime/.
  • Trait/interface constant merge should reuse existing trait merge paths; ensure enum TYPE_ENUM stores constants separately from case objects.
  • VM: FETCH_CLASS_CONSTANT / ClassConstFetch for enums must read enum constant table, not only case materialization.
  • Add test/compliance/cases/language/enum_class_constant.phpt + trait variant; JIT/AOT when enum const fetch is lowered.

Verification

  • Repro scripts above green on VM
  • Filter: vendor/bin/phpunit test/compliance/VMTest.php --filter enum_class_constant (after adding case)

Activity

  1. added
    enhancementNew feature or request
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 5, 2026
  2. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-B — starting this run

  3. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    Merged in #6415.

    Status: Enum user const, trait-merged constants, and interface-inherited constants on enums were already implemented on master (#5054, #5719, #5725, #6016). This PR added the missing maintainer repro script and wired enum_interface_const.phpt into EnumVMTest.

    Verification (all green):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro/maintainer_enum_class_constant.php
    php bin/vm.php test/repro/parity_enum_trait_const.php
    vendor/bin/phpunit test/compliance/EnumVMTest.php --filter "enum_class_constant|enum_interface_const"
    vendor/bin/phpunit test/compliance/EnumTraitConstTest.php
    '
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:compilerCompiler / CFG / JITarea: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