-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[RFC] Short list syntax #1849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Short list syntax #1849
Conversation
@@ -5,6 +5,8 @@ | |||
|
|||
list($a, list($b)) = array(new stdclass, array(new stdclass)); | |||
var_dump($a, $b); | |||
[$a, [$b]] = array(new stdclass, array(new stdclass)); | |||
var_dump($a, $b); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing test for error on [42] = ...
and similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not added many [] tests, it's using the exactly same syntax (array_pair_list) in parser and the differences are abstracted away inside AST.
If there would be a difference, I'd add tests, but here they would be just outright redundant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've added eight or so new error conditions and only one of them is currently covered.
I'm asking about [42] = ...
specifically because it's something the list() implementation would not necessarily check for (as it already had parser level checks for that).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, added list_008.phpt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case of interest may be [&$a] = ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah, list()
still doesn't support assignment by-reference. I'd wanted to fix that.
8672663
to
32eed27
Compare
32eed27
to
51582bf
Compare
51582bf
to
6e73c03
Compare
Just wondering, have you thought of this weird edge case? $a = "a";
$b = "b";
[$foo, $bar] = [$baz, $bat] = [$a, $b]; It's pretty ambigious - kind of hard to even assess what that means or what that would do. I don't know if there's a real use case where this would ever matter - I just thought of it so figured I'd bring it up in case there's a missing edge test-case or something. |
Behaves the same as with |
Well, good, but a test-case to prove that fact probably wouldn't hurt? :-) |
can this be closed? @bwoebi |
Yes, it has already been merged. |
Is there any specific reason why we don't support casts?
If don't, I'd like to propose it for our next version :) |
@carusogabriel no, there's no specific reason except that it hasn't been considered. Please create a RFC if you think it's a good idea (I'm not sure yet personally). |
Um where is the documentation for this? I am only seeing it here: Shouldnt it be here too?: |
See: https://wiki.php.net/rfc/short_list_syntax