Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:62277 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66473 invoked from network); 20 Aug 2012 06:36:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Aug 2012 06:36:12 -0000 Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.170 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 209.85.217.170 mail-lb0-f170.google.com Received: from [209.85.217.170] ([209.85.217.170:48921] helo=mail-lb0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9C/D1-03087-BDAD1305 for ; Mon, 20 Aug 2012 02:36:11 -0400 Received: by lbbgp3 with SMTP id gp3so3223321lbb.29 for ; Sun, 19 Aug 2012 23:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=DBdtaDzBkc5kzPTSyam29y+0kVg1e7J49tVsiJ0fCMA=; b=kqTskriFirE5stBZNNii72D09+keeXuWMm9sw5AA6xu3U815U/lFL1ce/Aiyl8DFZr 7kMLemnNEM04dkqq/YENzDVrFdupcxGfyWwOiDji6OQG89SzB/dQUzTeWiYHye4dHowC u7yaKpe3pnoskx4Lt30whAqY0Krc4i+Kg+MqZ02MyMc7Zs4UlbhnW5nCyBpTHANx7CLU +8mNHR0I/H+Z5mjgruWtyUaDNv0oKmb/EVUPAocdOQ6Z4AxrRECQu2FxGrZX0DIKFqu6 CiBhUPe0vfPRREM/4F8AtnxmYwmZfmOtIyFV/apuDJfXwNZtUeJNvQ8CPcdzTXvlr5xs fxVA== MIME-Version: 1.0 Received: by 10.112.88.106 with SMTP id bf10mr5685431lbb.43.1345444568653; Sun, 19 Aug 2012 23:36:08 -0700 (PDT) Received: by 10.112.8.7 with HTTP; Sun, 19 Aug 2012 23:36:08 -0700 (PDT) In-Reply-To: References: Date: Mon, 20 Aug 2012 02:36:08 -0400 Message-ID: To: Laruence Cc: Nikita Popov , PHP Internals Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] [VOTE]Call for voting: support use list in foreach From: theanomaly.is@gmail.com (Sherif Ramadan) On Sun, Aug 19, 2012 at 2:07 AM, Laruence wrote: > On Sat, Aug 18, 2012 at 5:48 PM, Nikita Popov wrote: >> On Sat, Aug 18, 2012 at 6:34 AM, Laruence 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.