Skip to content

Harden BackedEnum from()/tryFrom() lookup (#9603) - #9613

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-9603-enum-tryfrom-from
Jun 18, 2026
Merged

PurHur merged 1 commit into
masterfrom
agent/issue-9603-enum-tryfrom-from

Conversation

@PurHur

@PurHur PurHur commented Jun 18, 2026

Copy link
Copy Markdown
Owner

Summary

Related: #9575 fixed the primary regression on master; this hardens edge cases where case lookup could still miss valid backing values.

php-src reference

  • Zend/zend_enum.c — zend_enum_from(), backed-value case hash

PHP implementation

  • lib/VM/BackedEnum.php — constants fallback lookup
  • lib/VM/EnumFromHandler.php — runtime enum resolution

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
vendor/bin/phpunit test/unit/VmEnumFromTest.php --filter Issue9603
vendor/bin/phpunit test/unit/VmEnumCanonicalCaseVariableTest.php --filter testFromResolvesWhenEnumCasesTableEmpty
vendor/bin/phpunit test/compliance/EnumVMTest.php --filter "enum_try_from|enum_from"
php bin/vm.php test/repro/issue_9603_enum_from.php
php bin/vm.php test/repro/maintainer_enum_from_regression.php
'

Output:

OK (1 test, 1 assertion)   # Issue9603
OK (1 test, 2 assertions)  # empty enumCases fallback
OK (6 tests, 6 assertions)  # compliance enum_from/tryFrom
NULL / enum(E::A) / from ok  # issue repro
enum(Color::Red) ... (maintainer repro green)

Closes #9603

Made with Cursor

…).

When enumCases is empty or stale, resolve backing values from case constants and use the live runtime ClassEntry in EnumFromHandler so valid tryFrom/from calls return enum cases instead of null/ValueError.

Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur
PurHur merged commit 7d8a1ec into master Jun 18, 2026
@PurHur
PurHur deleted the agent/issue-9603-enum-tryfrom-from branch June 18, 2026 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Language: Enum::tryFrom()/from() — valid backing values return NULL / ValueError (Zend/zend_enum.c)

1 participant