From: Hannes Landeholm [mailto:landeh...@gmail.com] Sent: Tuesday, June 07, 2011 11:50 AM To: John Crenshaw; internals@lists.php.net Subject: Re: [PHP-DEV] Inline constructing/cloning and inline foreach listing
On 7 June 2011 15:53, John Crenshaw <johncrens...@priacta.com<mailto:johncrens...@priacta.com>> wrote: > foreach ($arrays as list($e1, $e2, $e3)) { ... Disagree. This feels very obtuse. I wouldn't expect this construct to work at all, and even if it did, it is highly ambiguous (I.E. at first I thought you were intending to grab 3 entries at a time, rather than extracting entries from a second array). John Crenshaw Priacta, Inc. I don't understand what's ambiguous? For each iteration the foreach assigns the current value to the variable $value specified as either "as $key => $value" or "as $value". The "as" keyword is simply a type of assignment operator that assigns the current element to the right expression. Since PHP has a special "list()" language construct for assignment it doesn't make sense that "list(...) = $something" assignment would work but not "array($something) as list(...)". Grabbing "3 elements at a time" is not logical at all. Why would the list construct change how the foreach iterates? Hannes The proposed meaning IS the more logical of the two, but that didn't stop me from being confused when I first looked at the construction. Like I said, at first glance I thought you were trying to iterate 3 at a time and I thought "why would we want the language to support THAT?" In any case, I'm just one person, and I don't entirely care for list() in the first place so I'm probably biased, but this construct seems wrong to me. John Crenshaw Priacta, Inc.