Repository navigation
Fix integer key renumbering in constant array unpacking - #1174
Merged
Merged
Conversation
nikic
reviewed
Oct 4, 2026
| $array = array_merge($array, $this->evaluate($item->value)); | ||
| $unpacked = $this->evaluate($item->value); | ||
| if (!is_array($unpacked)) { | ||
| throw new \TypeError('Unpacked value must be an array'); |
Owner
There was a problem hiding this comment.
Suggested change
| throw new \TypeError('Unpacked value must be an array'); | |
| throw new \Error('Only arrays can be unpacked in constant expression'); |
To match the error produced by PHP, based on: https://github.com/php/php-src/blob/f73ab1c244adf57058279adb72d7b6bf40d09a96/Zend/zend_ast.c#L637.
Contributor
Author
There was a problem hiding this comment.
Thank you. Updated the exception to \Error with the matching message, and adjusted the test to check the message as well.
ydah
force-pushed
the
fix-array-unpack-keys
branch
from
October 5, 2026 06:11
1e3c062 to
a7c1415
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.
ConstExprEvaluatorusesarray_merge()for array unpacking, which renumbers existing integer keys:Append unpacked integer-keyed values and assign string-keyed values directly, preserving existing keys and matching PHP's behavior. Even an empty unpack (
[5 => "a", ...[]]) now preserves key5.