Skip to content

Stdlib: constant() must resolve enum case constants (E::A, dynamic E::$name) (zend_constants.c) #5682

Description

@PurHur

Category

stdlib

Problem

constant('Class::CONST') for user classes is tracked in #3484. Enum case constants are a separate lookup path in Zend (zend_enum_get_case_by_name, class constant table). This compiler fatals on VM when resolving enum cases:

  • constant('E::A') — uncaught VM fatal (not Error: Undefined constant)
  • constant('E::'.$c) — same

Zend returns the enum case object (\E::A).

php-src reference

Repro

<?php
enum E: int { case A = 1; }
var_export(constant('E::A'));
echo "\n";
$c = 'A';
var_export(constant('E::'.$c));
echo "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro.php'
php repro.php
Engine Output
Zend \E::A twice
This compiler VM fatal in ExceptionSupport (enum constant unresolved)

Scope (this repo)

Layer Path
VM ext/standard/constant_.php, ext/standard/VmConstants.php (or enum registry)
Enum registry lib/VM/EnumCaseSupport.php, enum ClassEntry case map
JIT ext/standard/JitConstant.php — phase 2 literal names only
Tests test/compliance/cases/stdlib/constant_enum_case.phpt

Done when

  • Repro prints \E::A for literal and dynamic names
  • Missing case constant('E::Z') → Error: Undefined constant "E::Z"
  • ./script/ci-fast.sh --filter constant_enum green

Related

Activity

  1. added
    enhancementNew feature or request
    phase-4:stdlibPhase 4 – stdlib for web apps
    area:vmVirtual machine
    implementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claim
    on Jun 4, 2026
  2. PurHur commented on Jun 13, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  3. PurHur commented on Jun 13, 2026

    @PurHur
    OwnerAuthor

    Unclaiming: constant('E::A') enum case resolution already green on master (#5926). VM repro returns \E::A for literal + dynamic names. Recommend closing as duplicate of #3484 phase 2.

  4. PurHur commented on Jun 15, 2026

    @PurHur
    OwnerAuthor

    claim: PHP Compiler STD Lib — starting this run

  5. PurHur commented on Jun 15, 2026

    @PurHur
    OwnerAuthor

    Merged via #8627

    Fix: constant('C::X') when C::X = E::A canonicalizes enum case singletons via EnumCaseSupport::materializeConstantValue(); enum === compares FQCN + case name (not compile-time ClassEntry stub identity).

    Verification (green):

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
    php bin/vm.php test/repro-maintainer/parity_constant_class_enum_const.php
    ./vendor/bin/phpunit --filter constant_class_enum
    php bin/compile.php -l test/repro-maintainer/parity_constant_class_enum_const.php'

    → same / OK (1 test) / exit 0

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-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions