Skip to content

[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

Closed
wants to merge 1 commit into from
Closed

Conversation

bwoebi
Copy link
Member

@bwoebi bwoebi commented Apr 5, 2016

@@ -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);
Copy link
Member

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.

Copy link
Member Author

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.

Copy link
Member

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).

Copy link
Member Author

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

Copy link
Member

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] = ...

Copy link
Contributor

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.

@bwoebi bwoebi force-pushed the rectangular_lists branch from 8672663 to 32eed27 Compare April 7, 2016 13:33
@bwoebi bwoebi force-pushed the rectangular_lists branch from 32eed27 to 51582bf Compare April 27, 2016 19:11
@bwoebi bwoebi force-pushed the rectangular_lists branch from 51582bf to 6e73c03 Compare April 27, 2016 19:18
@mindplay-dk
Copy link

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.

@hikari-no-yume
Copy link
Contributor

Behaves the same as with list($foo, $bar) = list($baz, $bat) = [$a, $b];

@mindplay-dk
Copy link

Well, good, but a test-case to prove that fact probably wouldn't hurt? :-)

@laruence
Copy link
Member

can this be closed? @bwoebi

@nikic
Copy link
Member

nikic commented May 28, 2016

Yes, it has already been merged.

@nikic nikic closed this May 28, 2016
@carusogabriel
Copy link
Contributor

carusogabriel commented Sep 20, 2018

Is there any specific reason why we don't support casts?

[(int) $x, (float) $y] = ['123', '456'];

If don't, I'd like to propose it for our next version :)

@bwoebi
Copy link
Member Author

bwoebi commented Sep 20, 2018

@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).

@ghost
Copy link

ghost commented Oct 20, 2019

Um where is the documentation for this? I am only seeing it here:

https://www.php.net/manual/en/migration71.new-features.php#migration71.new-features.symmetric-array-destructuring

Shouldnt it be here too?:

https://www.php.net/language.operators.assignment

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.

6 participants