Language: BackedEnum::from() / tryFrom() (#3114) - #3152
Merged
Conversation
Owner
Author
Maintainer local verify (Docker
|
This was referenced May 29, 2026
PurHur
force-pushed
the
agent/issue-3114-enum-from
branch
from
May 30, 2026 23:02
6ae808d to
0d71ebe
Compare
Implement zend_enum_from_case-style lookup for backed enums, enum case values with name/value properties, and clear callArgEntries after internal handlers so chained static calls receive the correct arguments. Co-authored-by: Cursor <cursoragent@cursor.com>
Internal handlers route ValueError through executeInternalHandler → raiseUncaughtException (Exception), matching other runtime builtins until native ValueError propagation lands (#195). Co-authored-by: Cursor <cursoragent@cursor.com>
Guards int backing type lookup alongside existing string enum_from/try_from cases. php-src: Zend/zend_enum.c zend_enum_from_case(). Co-authored-by: Cursor <cursoragent@cursor.com>
Match php-src zend_enum.c message format (enum name unquoted) and add enum_from_invalid.phpt plus caught ValueError unit coverage. php-src: Zend/zend_enum.c — zend_enum_from_case() Co-authored-by: Cursor <cursoragent@cursor.com>
Normalize int-backed numeric strings and scalar coercions before case
lookup so Level::from('1') matches Zend; reject non-numeric strings with
TypeError. Adds unit coverage for int string acceptance and bad input.
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Run enum overlay chain before typed-class-const so Op\Stmt\Enum_ receives int $flags before attributes. Tighten abstract-patch skip detection and guard with ApplyPatchesTest. Co-authored-by: Cursor <cursoragent@cursor.com>
apply_php_cfg_enum_class_method_parser_fix() is invoked without an argument from apply_php_cfg_enum_early_chain(); default to vendor Parser.php like sibling helpers to avoid set -u unbound $1 abort. Co-authored-by: Cursor <cursoragent@cursor.com>
apply_php_cfg_enum_overlay copies the flags-bearing Enum_.php overlay then may return early without updating Parser.php, leaving vendor in a state where Op\Stmt\Enum_ expects int $flags but parseStmt_Enum passes attributes as argument #5. Add php_cfg_sync_enum_flags_parser() and invoke it from enum overlay paths and the early chain. Co-authored-by: Cursor <cursoragent@cursor.com>
Map materialized VM Throwable objects to native PHP exceptions in raiseUncaughtException so BackedEnum::from() invalid values throw ValueError (not generic Exception) per Zend parity. php-src: Zend/zend_enum.c — zend_enum_from_case() Co-authored-by: Cursor <cursoragent@cursor.com>
PurHur
force-pushed
the
agent/issue-3114-enum-from
branch
from
May 31, 2026 08:41
7bd4739 to
54fb12e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
VM lowering for backed enum
::from()and::tryFrom()with case lookup by backing value (Zendzend_enum.cparity).BackedEnum::caseForValue()iteratesClassEntry::enumCases[]with int/string backing coercionEnumFromHandlerinternal builtin dispatched frominitStaticCallableValueError/TypeErrorbridged into user catch viaexecuteInternalHandler(Runtime: intdiv() division by zero — void context silent + uncatchable in try/catch (Zend zend_exceptions.c parity) #3648)VmEnumFromTest(string + int backed, invalid value, caught/uncaught paths)apply-patches.shwhen patch already appliedphp-src reference
Zend/zend_enum.c—zend_enum_from_case(),zend_try_enum_from_case()Zend/zend_interfaces.c—BackedEnuminternal APIVerification
Note:
enum_instanceof.phptfailure is pre-existing on master (#3550), unrelated to this PR. JIT deferred per issue scope.Closes #3114