Skip to content

Language: enum type constants — public const on enum declaration missing (PHP 8.3) #6590

Closed

Description

@PurHur

Category

language · PHP 8.3 enum constants

Problem

PHP 8.3+ allows typed constants on enum declarations separate from cases:

enum E: string {
    case A = 'a';
    public const X = 'meta';
}
echo E::X; // "meta"

Zend resolves E::X at compile/runtime. This compiler reports Undefined class constant E::X (fatal) — enum-level constants are not materialized.

Verified probe (2026-06-06):

Call Zend PHP 8.2 VM (today)
enum E: string { case A="a"; public const X="x"; } echo E::X; x Fatal error: Undefined class constant E::X

php-src reference

Repro

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php -r "enum E: string { case A=\"a\"; public const X=\"x\"; } echo E::X;"'

Scope

Module Path
Compiler enum compile — register non-case constants on enum scope
VM FETCH_CLASS_CONSTANT / enum symbol table for E::X
JIT/AOT enum constant fetch lowering
Tests test/compliance/cases/language/enum_type_constant.phpt

Done when

  • public const (and private/protected where valid) on enums resolve like Zend
  • constant('E::X'), defined('E::X'), and reflection can see enum constants (follow-up ok in separate reflection issue if needed)
  • Case constants (case A = 1) unchanged

Verification

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

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 6, 2026
  2. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    claim: worker-lane-c — starting this run

  3. PurHur commented on Jun 6, 2026

    @PurHur
    OwnerAuthor

    Merged via #6599.

    Enum `public const` on backed enums already resolves on VM/JIT (landed with #6407 / #6415). This run added the missing compliance guard and maintainer repro from the issue acceptance criteria.

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

    OK (2 tests, 2 assertions)

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php test/repro/maintainer_enum_type_constant.php'

    x / x / defined

    ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/jit.php test/repro/maintainer_enum_type_constant.php'

    x / x / defined

    ```

    AOT backed-enum compile still segfaults (pre-existing; `enum_backed.phpt` exit 139) — separate from this language parity ticket.

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