[RFC][Discussion] - list() reference syntax

php.internals

David Walker

9 years ago
Hi All, I had mentioned the other day my desire to look at, and attempt implementation of allowing by-reference assignment within list()'s. Andrea had created an RFC for this purpose 2+years ago, but withdrew it due to problems with implementation with the parsing/compiler of PHP 5. I've taken a shot at implementing this feature within PHP7 and have commandeered the RFC and would like to re-open it for discussion. I've attached to the RFC my current implementation which seems to be working in the cases I can think of. I'd be interested to hear from the community about if this feature is still desirable, and if so, if there are list() cases that I haven't thought about yet for test cases. RFC (sorry for awkward formatting, not sure if the issues with links in messages & mailinglist are fixed yet): wiki php net/rfc/list_reference_assignment Cheers
-- Dave

David Walker

9 years ago
[Sorry if this is a second time you get this, but email issues and all] Hi All, I had mentioned the other day my desire to look at, and attempt implementation of allowing by-reference assignment within list()'s. Andrea had created an RFC for this purpose 2+years ago, but withdrew it due to problems with implementation with the parsing/compiler of PHP 5. I've taken a shot at implementing this feature within PHP7 and have commandeered the RFC and would like to re-open it for discussion. I've attached to the RFC my current implementation which seems to be working in the cases I can think of. I'd be interested to hear from the community about if this feature is still desirable, and if so, if there are list() cases that I haven't thought about yet for test cases. RFC (sorry for awkward formatting, not sure if the issues with links in messages & mailinglist are fixed yet): http://wiki.php.net/rfc/list_reference_assignment Cheers
-- Dave

David Walker

9 years ago
On Wed, Jan 11, 2017 at 8:43 AM David Walker <dave@mudsite.com> wrote:
> [Sorry if this is a second time you get this, but email issues and all] > > Hi All, > > I had mentioned the other day my desire to look at, and attempt > implementation of allowing by-reference assignment within list()'s. Andrea > had created an RFC for this purpose 2+years ago, but withdrew it due to > problems with implementation with the parsing/compiler of PHP 5. I've > taken a shot at implementing this feature within PHP7 and have commandeered > the RFC and would like to re-open it for discussion. > > I've attached to the RFC my current implementation which seems to be > working in the cases I can think of. I'd be interested to hear from the > community about if this feature is still desirable, and if so, if there are > list() cases that I haven't thought about yet for test cases. > > RFC (sorry for awkward formatting, not sure if the issues with links in > messages & mailinglist are fixed yet): > http://wiki.php.net/rfc/list_reference_assignment > > Cheers > -- > Dave >
I'd like to open this RFC to voting in the next week or so. I know that I had sent the notice for discussion during the list-serve problems earlier this month, but there has been limited comment over the past couple weeks. Unsure if that means there's little interest, or, just missed everyone, or is perfect as is (!! well, we could hope right?). So if there's any discussion now's a good time, otherwise I'd like to open it to voting early next week. Cheers
-- Dave

Andrew Faulds

9 years ago
Hi Dave, Regarding the =& open issue in the RFC, I don't think the =& syntax makes sense to me. The thing on the right-hand side of a list() assignment is the array, not its values. It makes no difference for the purposes of assigning from its values if the array is a reference or not, so I'd expect the & here to do nothing at all. So, having the &s only on the left-hand side makes more sense to me. I think supporting =& would be a potential source of confusion. On a different note, the RFC doesn't mention support for the shorthand list() syntax introduced in 7.1 (i.e. `[&$a, &$b, &$c] = $arr;`). Since it shares its implementation with list(), I assume it is indeed supported, but you should probably explicitly whether or not it is, for clarity's sake. Thanks for your work on this! I'm glad to see it revived. :)
-- Andrea Faulds https://ajf.me/

David Walker

9 years ago
On Wed, Jan 11, 2017 at 3:15 PM Andrea Faulds <ajf@ajf.me> wrote:
> Regarding the =& open issue in the RFC, I don't think the =& syntax > makes sense to me. The thing on the right-hand side of a list() > assignment is the array, not its values. It makes no difference for the > purposes of assigning from its values if the array is a reference or > not, so I'd expect the & here to do nothing at all. So, having the &s > only on the left-hand side makes more sense to me. I think supporting =& > would be a potential source of confusion. >
Duly noted. I too would prefer not to implement it as well, keeping just one supported syntax. Although, since both syntaxes were raised as potential implementations in the bugs I thought it would be something to at least ask everyone to consider. Better to raise the subject and have everyone concur not to do it, than to ignore it, imo. Going forward, I guess I'd like to know if anyone -would- want to support it.
> On a different note, the RFC doesn't mention support for the shorthand > list() syntax introduced in 7.1 (i.e. `[&$a, &$b, &$c] = $arr;`). Since > it shares its implementation with list(), I assume it is indeed > supported, but you should probably explicitly whether or not it is, for > clarity's sake. >
Yup, you're right. list() = and [] = do seem to follow the same compilation/execution so there's no difference. I'll make sure to note it in the RFC just to note. Cheers
-- Dave