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
Ref: #1492
Category
language· php-src-strictProblem
On a backed enum case value, the
::classpseudo-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, soE::A::classfatals:TypeError: Cannot use "::class" on value of type stringphp-src reference
Zend/zend_enum.c— enum case object handlers (zend_enum_get_class_namepath)Zend/zend_compile.c—ZEND_FETCH_CLASS_NAMEon enum case receiversZend/tests/enums/—::classon case valuesRepro
In-tree:
test/repro/maintainer_gap_enum_case_class_constant.phpE::A::classstring(1) "E"TypeError: Cannot use "::class" on value of type string❌Scope (this repo)
lib/Compiler.php::classon enum-case operands to enum FQCN without requiring object receiverlib/VM/EnumCaseSupport.phptest/compliance/cases/language/enum_case_class_const.phptRelated enum-object preservation: #9436, #9475, #9289.
Done when
string(1) "E"on VM (php-src-strict)::classappears in compiled scripts./script/ci-fast.sh --filter enum_case_classRef: #1492