Skip to content

Regression: enum case ::class — operand still backing int after #9827 (Zend/zend_compile.c) #9830

Description

@PurHur

Category

language · php-src-strict · regression (re-#9811, merged #9827)

Problem

E::Case::class must return the enum FQCN string on enum case operands. #9827 added tests and resolveClassPseudoConstFromOperand() for TYPE_ENUM_CASE, but direct TYPE_CLASS_CONST_FETCH on E::A::class still sees the class operand as a backing scalar int — resolveClassPseudoConstFromOperand() returns null and VM emits:

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

Root cause: enum case fetch at use-site materializes backing value before ::class pseudo-constant resolution (same enum-preservation cluster as #9727, #9712).

php-src reference

Repro (failure on master 2026-06-19)

<?php
enum E: int { case A = 1; case B = 2; }
echo E::A::class, "\n";
echo (E::B)::class, "\n";
$a = E::A;
echo $a::class, "\n";
enum U { case C; }
echo U::C::class, "\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/maintainer_enum_case_class_pseudo.php
'
Engine Output
Zend PHP 8.3+ four lines: E, E, E, U
VM today Fatal TypeError on first E::A::class

Existing guard file: test/repro/maintainer_enum_case_class_pseudo.php.

Scope (this repo)

Layer Path
Compiler lib/Compiler.php — preserve enum case object (or dedicated opcode) through ::class fetch
VM lib/VM.php — TYPE_CLASS_CONST_FETCH + resolveClassPseudoConstFromOperand()
JIT lib/JIT.php — same identity rules when lowering fetch
Tests extend test/compliance/cases/language/enum_case_class_pseudo.phpt

PHP-in-PHP only — no new C runtime branches.

Done when (php-src-strict)

  • Repro prints four FQCN lines on VM matching Zend
  • Parenthesized, variable, and unit-enum cases from maintainer repro stay green
  • ./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter enum_case_class_pseudo' green
  • ./script/ci-fast.sh --filter enum_case_class_pseudo green

Related

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

    IMPORTANTCritical patharea: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