Category
language
Problem
Backed enums compile (#1356), but BackedEnum::from() / tryFrom() validation is missing or incomplete. Zend maps a scalar to the matching case or throws ValueError / returns null.
php-src reference
Repro (today)
Save as repro_enum_from.php (same shape as test/compliance/cases/language/enum_basic.phpt):
<?php
enum Color: string {
case Red = 'red';
case Blue = 'blue';
}
echo Color::from('red')->name;
echo Color::tryFrom('nope') === null ? 'null' : 'bad';
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro_enum_from.php'
| Runtime |
Expected output |
| Zend PHP |
Rednull |
| This compiler (May 2026) |
LogicException / wrong case / compile or php-cfg parse failure before dispatch |
Observed (2026-05-29 harness)
On some harness images, enum TUs fail early in php-cfg with:
PHPCfg\Op\Stmt\Enum_::__construct(): Argument #3 ($implements) must be of type array, PHPCfg\Block given
Worker baseline before implementing from/tryFrom:
./script/ci-fast.sh --filter VmEnumBasicTest
./script/ci-fast.sh --filter enum_basic
If enum parse fails in Docker, run script/apply-patches.sh in the image and re-check; do not stub from() with internal_*.
Scope
| Area |
Path |
| VM |
lib/VM.php — backed enum case table lookup |
| Compiler |
lib/Compiler.php — Enum::from / tryFrom static call lowering |
| Tests |
test/compliance/cases/language/enum_from.phpt, enum_try_from.phpt |
| JIT/AOT |
after VM green; coordinate #3076 AOT enum metadata |
Done when
Links
Labels
implementation-ready
Category
languageProblem
Backed enums compile (#1356), but
BackedEnum::from()/tryFrom()validation is missing or incomplete. Zend maps a scalar to the matching case or throwsValueError/ returnsnull.php-src reference
Zend/zend_enum.c—zend_enum_from_case(),zend_try_enum_from_case()Zend/zend_interfaces.c—BackedEnuminternal APIZend/zend_enum.stub.php—from/tryFromsignaturesRepro (today)
Save as
repro_enum_from.php(same shape astest/compliance/cases/language/enum_basic.phpt):./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && php bin/vm.php repro_enum_from.php'RednullLogicException/ wrong case / compile or php-cfg parse failure before dispatchObserved (2026-05-29 harness)
On some harness images, enum TUs fail early in php-cfg with:
Worker baseline before implementing
from/tryFrom:If enum parse fails in Docker, run
script/apply-patches.shin the image and re-check; do not stubfrom()withinternal_*.Scope
lib/VM.php— backed enum case table lookuplib/Compiler.php—Enum::from/tryFromstatic call loweringtest/compliance/cases/language/enum_from.phpt,enum_try_from.phptDone when
from('red')returnsColor::Red; invalid scalar →ValueErrorwith Zend-like messagetryFrom('nope')returnsnullwithout throw./script/ci-fast.sh --filter enum_fromgreenenum_basic.phpt/VmEnumBasicTestLinks
cases()), Language: Backed enum declarations AOT lowering (#1356 phase 2) #3076 (AOT) · Epic: Self-host critical path — compiler compiles itself (M3→M5) #1492Labels
implementation-ready