On Sun, Aug 19, 2012 at 2:07 AM, Laruence <larue...@php.net> wrote: > On Sat, Aug 18, 2012 at 5:48 PM, Nikita Popov <nikita....@gmail.com> wrote: >> On Sat, Aug 18, 2012 at 6:34 AM, Laruence <larue...@php.net> wrote: >>> Hi: >>> This feature introduces list() support in foreach constructs(more >>> info can be found here: https://wiki.php.net/rfc/foreachlist). >>> >>> please vote for this: https://wiki.php.net/rfc/foreachlist#vote >> >> Hi Lauruence! >> >> Is this vote just for list() or also for error suppression? I'd vote >> +1 on the first, but -1 on the second, so it would be nice to make it >> more clear ;) > Hi, > > okey, I opened another vote for the foreach list with silent token > supporting. > > thanks > >> >> Nikita > > >
Sorry, I feel like I missed the discussion phase of this RFC. I'm unclear about how this behavior in the construct will affect existing code. Currently, you can only use list() with arrays that have sequential numeric keys starting from 0. So the follow does not currently work with the list construct... list($x, $y) = array('x'=>1, 'y'=>2); // This won't work /* This won't work either.. at least not the way I'd expect because $y will end up being 1 and $x will be null and an E_NOTICE level error is thrown. */ list($x, $y) = array(1=>1, 2=>2); var_dump($x, $y); /* NULL int(1) */ While I see the use of the list construct as a minor improvement in readability (it does add some syntactic sugar), I also can't imagine that it makes things any more consistent, which is one of the points of this RFC. This also means that if we chose to avoid this extra level of indirection by way of list in foreach constructs we can't expect to access the key, which might make for another ambiguity and lead us back to just using something like the following... $array = array( 'Cape Cod' => array('lat' => 12.20, 'long' => 34.60), 'North Shore' => array('lat' => 18.72, 'long' => 4.11), 'Mount Erie' => array('lat' => 6.02, 'long' => 21.79), ); foreach ($array as $point => $coordinates) { $lat = $coordinates['lat']; $long = $coordinates['long']; echo "Coordinates for $point are: LAT = $lat, LONG = $long\n"; } I understand we can simply say this would not be an ideal use case for this, but then it becomes a tiny variation in syntax that only solves a specific problem. -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php