Skip to content

Language: defined('Enum::CASE') — enum cases must be detectable (zend_constants.c) #4972

Closed

Description

@PurHur

Category

language / stdlib — enum constant table + defined()

Problem

For backed/unit enums, Zend treats EnumName::CASE as a defined constant name for defined() and constant() (returns the enum case object). This compiler returns false from defined('E::A') even when E::A exists, and constant('E::A') throws Undefined constant.

Blocks reflection/bootstrap code that probes enum cases by name without hard-coding case objects.

php-src reference

Repro

<?php
enum E: int {
    case A = 1;
    case B = 2;
}
var_dump(defined('E::A'));
var_dump(defined('E::Z'));
var_dump(constant('E::A'));
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php repro.php
php bin/vm.php repro.php
'
Check Zend This compiler VM
defined('E::A') bool(true) bool(false) ❌
defined('E::Z') bool(false) bool(false) ✅
constant('E::A') enum(E::A) Undefined constant "E::A" ❌

Scope

Layer Path Notes
VM enum registration / constant lookup Register case names like class constants
Stdlib ext/standard/defined_.php, constant_.php Qualified Class::MEMBER path (#3484) must include enum cases
Tests defined_enum_case.phpt, extend constant_class.phpt Backed + unit enums

Done when

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

    @PurHur
    OwnerAuthor

    claim: cursor-agent-lane-b — starting this run

  3. added a commit that references this issue on Jun 5, 2026
    11495c6
  4. PurHur commented on Jun 5, 2026

    @PurHur
    OwnerAuthor

    Merged via #6020.

    Verification:

    • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php -r "enum E: int { case A = 1; } var_dump(defined("E::A"));"'
    • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter defined_enum'
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 featuresphase-4:stdlibPhase 4 – stdlib for web apps

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions