Repository navigation
Conversation
bwoebi
force-pushed
the
destructuring-coalesce
branch
2 times, most recently
from
October 14, 2022 14:43
95f5d27 to
5c8e498
Compare
bwoebi
force-pushed
the
destructuring-coalesce
branch
from
October 14, 2022 14:44
5c8e498 to
c79b933
Compare
|
Is it like? <?php
['a'=>$a, 'b'=>$b] = [...json_decode('{"a":2}', 1), ...['b'=>'def val']];
var_dump($a, $b); |
Member
Author
|
@kandy In that particular scenario of a top-level dimension with string keys, where no null values are present, yes. But array unpacking won't help you with integer keys (because it will re-index them, consecutively), it doesn't allow for any nested destructuring, is not usable inline as a foreach target, and does not handle nulls for you. |
|
I like it! But what should happen if: It also supports ?: operator? |
Contributor
|
I found this PR when looking for another. The RFC was declined, so I think this one can be closed. |
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.
Allowing for
[$a ?? $b] = $array;, where $a is assigned $b if the key in the array is null or missing.RFC: https://wiki.php.net/rfc/destructuring_coalesce