Skip to content

Language: enum case value ::class must return enum name — VM TypeError on backing scalar (Zend/zend_enum.c) #9518

Description

@PurHur

Category

language · php-src-strict

Problem

On a backed enum case value, the ::class pseudo-constant must resolve to the enum type name (e.g. "E"). Zend treats enum cases as objects for this operation. This compiler stores cases as backing scalars at runtime, so E::A::class fatals:

TypeError: Cannot use "::class" on value of type string

php-src reference

Repro

In-tree: test/repro/maintainer_gap_enum_case_class_constant.php

<?php
enum E: string { case A = 'a'; }
var_dump(E::A::class);
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php test/repro/maintainer_gap_enum_case_class_constant.php
php bin/vm.php test/repro/maintainer_gap_enum_case_class_constant.php 2>&1 | head -4
'
Engine E::A::class
Zend PHP 8.2 string(1) "E"
VM today TypeError: Cannot use "::class" on value of type string ❌

Scope (this repo)

Path Work
lib/Compiler.php Lower ::class on enum-case operands to enum FQCN without requiring object receiver
lib/VM/EnumCaseSupport.php If resolved at runtime, accept enum-case zvals and return declaring enum name
JIT/AOT Same semantics via shared helper (do not LLVM-special-case per issue)
Tests test/compliance/cases/language/enum_case_class_const.phpt

Related enum-object preservation: #9436, #9475, #9289.

Done when

  • Repro prints string(1) "E" on VM (php-src-strict)
  • JIT/AOT match when ::class appears in compiled scripts
  • Compliance PHPT guard green in ./script/ci-fast.sh --filter enum_case_class

Ref: #1492

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