Category
language · php-src-strict
Problem
#3114 closed with VM handlers in lib/VM/EnumFromHandler.php and lib/VM/BackedEnum.php, but BackedEnum::from() / ::tryFrom() are broken at runtime: every lookup returns no match and from() throws ValueError even for exact backing scalars. tryFrom() returns null for valid values.
This blocks enum deserialization, config mapping, and any code using the standard backed-enum factory API.
php-src reference
Repro
Save as test/repro/maintainer_enum_from_regression.php:
<?php
declare(strict_types=1);
enum Color: string { case Red = 'red'; case Blue = 'blue'; }
enum Count: int { case One = 1; case Two = 2; }
// string-backed — exact match
var_dump(Color::from('red'));
var_dump(Color::tryFrom('red'));
// int-backed — int and numeric-string coercion
var_dump(Count::from(1));
var_dump(Count::tryFrom('1'));
// invalid — from throws ValueError, tryFrom null
try {
Color::from('nope');
echo "from_invalid_ok\n";
} catch (ValueError $e) {
echo 'from_invalid: ', $e->getMessage(), "\n";
}
var_dump(Color::tryFrom('nope'));
Commands
php test/repro/maintainer_enum_from_regression.php
php bin/vm.php test/repro/maintainer_enum_from_regression.php
Verified (2026-06-18, host PHP 8.2 vs bin/vm.php)
| Probe |
Zend |
VM today |
Color::from('red') |
enum(Color::Red) |
ValueError: "red" is not a valid backing value for enum Color |
Color::tryFrom('red') |
enum(Color::Red) |
NULL |
Count::from(1) |
enum(Count::One) |
ValueError: 1 is not a valid backing value for enum Count |
Count::tryFrom('1') |
enum(Count::One) |
NULL |
Color::from('nope') |
ValueError |
ValueError (message OK) |
Color::tryFrom('nope') |
NULL |
NULL |
Scope (PHP-in-PHP)
| Layer |
Path |
| VM lookup |
lib/VM/BackedEnum.php — caseForValue(), backingValuesMatch(), caseBackingScalar() vs ClassEntry::$enumCases storage |
| Handler |
lib/VM/EnumFromHandler.php |
| Enum registration |
lib/VM/EnumSupport.php, lib/Compiler.php enum compile path — ensure case backing values visible to lookup |
| JIT |
lib/JIT/BackedEnumFromJit.php, lib/JIT/EnumFromHelper.php — must match VM after fix |
| Tests |
test/compliance/cases/language/enum_from.phpt (restore/extend post-#3114) |
No new C in runtime/ — fix enum case table + PHP helpers only.
Done when (php-src-strict)
Related
Category
language· php-src-strictProblem
#3114 closed with VM handlers in
lib/VM/EnumFromHandler.phpandlib/VM/BackedEnum.php, butBackedEnum::from()/::tryFrom()are broken at runtime: every lookup returns no match andfrom()throwsValueErroreven for exact backing scalars.tryFrom()returnsnullfor valid values.This blocks enum deserialization, config mapping, and any code using the standard backed-enum factory API.
php-src reference
Zend/zend_enum.c—zend_enum_from_case(),zend_try_enum_from_case()Zend/zend_enum.stub.php—BackedEnum::from/tryFromZend/zend_interfaces.c— internalBackedEnumAPIRepro
Save as
test/repro/maintainer_enum_from_regression.php:Commands
Verified (2026-06-18, host PHP 8.2 vs
bin/vm.php)Color::from('red')enum(Color::Red)ValueError: "red" is not a valid backing value for enum ColorColor::tryFrom('red')enum(Color::Red)NULLCount::from(1)enum(Count::One)ValueError: 1 is not a valid backing value for enum CountCount::tryFrom('1')enum(Count::One)NULLColor::from('nope')ValueErrorValueError(message OK)Color::tryFrom('nope')NULLNULLScope (PHP-in-PHP)
lib/VM/BackedEnum.php—caseForValue(),backingValuesMatch(),caseBackingScalar()vsClassEntry::$enumCasesstoragelib/VM/EnumFromHandler.phplib/VM/EnumSupport.php,lib/Compiler.phpenum compile path — ensure case backing values visible to lookuplib/JIT/BackedEnumFromJit.php,lib/JIT/EnumFromHelper.php— must match VM after fixtest/compliance/cases/language/enum_from.phpt(restore/extend post-#3114)No new C in
runtime/— fix enum case table + PHP helpers only.Done when (php-src-strict)
var_dumplines match Zend (enum(...)/ notNULL)from/tryFrombehavior unchanged (ValueError / null)php bin/jit.phprepro matches VM when JIT lowering enabled (Language: BackedEnum::from() / tryFrom() — JIT/AOT scalar lookup (phase 2 of #3114) #4053)./script/ci-fast.sh --filter enum_fromgreenRelated