Category
language | php-src-strict
Problem
BackedEnum::from($invalid) must throw ValueError: {value} is not a valid backing value for enum {Enum}. The VM emits Method call on non-object instead — wrong exception and message; likely enum case/scalar confusion in static enum method dispatch.
php-src reference
Repro
test/repro/enum_from_invalid.php:
<?php
enum E: int { case A = 1; }
try {
E::from(99);
} catch (Throwable $e) {
echo get_class($e) . ': ' . $e->getMessage();
}
echo "\n";
source script/php-env.sh
php test/repro/enum_from_invalid.php
php bin/vm.php test/repro/enum_from_invalid.php
| Call |
Zend |
VM today |
E::from(99) |
ValueError: 99 is not a valid backing value for enum E |
Method call on non-object |
E::tryFrom(99) |
null |
verify same dispatch path |
Scope (PHP-in-PHP)
| Layer |
Path |
| VM |
BackedEnum::from / tryFrom builtins under enum static dispatch |
| Shared |
lib/VM/EnumCaseSupport.php — preserve enum class entry for static calls |
| Tests |
test/compliance/cases/language/backed_enum_from_value_error.phpt |
Done when (php-src-strict)
Related
#9876 · #9846 · #9847 · #9730 · #1492
Category
language| php-src-strictProblem
BackedEnum::from($invalid)must throwValueError: {value} is not a valid backing value for enum {Enum}. The VM emitsMethod call on non-objectinstead — wrong exception and message; likely enum case/scalar confusion in static enum method dispatch.php-src reference
Zend/zend_enum.c—zim_BackedEnum_from,zend_enum_from_baseZend/zend_enum.stub.php—BackedEnum::from()/tryFrom()Repro
test/repro/enum_from_invalid.php:source script/php-env.sh php test/repro/enum_from_invalid.php php bin/vm.php test/repro/enum_from_invalid.phpE::from(99)ValueError: 99 is not a valid backing value for enum EMethod call on non-objectE::tryFrom(99)nullScope (PHP-in-PHP)
BackedEnum::from/tryFrombuiltins under enum static dispatchlib/VM/EnumCaseSupport.php— preserve enum class entry for static callstest/compliance/cases/language/backed_enum_from_value_error.phptDone when (php-src-strict)
ValueErrorwith Zend message on VMtryFrom()returnsnullfor invalid, case object for validcases()) tracked separatelyRelated
#9876 · #9846 · #9847 · #9730 · #1492