Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:90706 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38542 invoked from network); 19 Jan 2016 01:35:14 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 19 Jan 2016 01:35:14 -0000 X-Host-Fingerprint: 90.212.141.145 unknown Received: from [90.212.141.145] ([90.212.141.145:2790] helo=localhost.localdomain) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 12/0F-20254-2D29D965 for ; Mon, 18 Jan 2016 20:35:14 -0500 Message-ID: <12.0F.20254.2D29D965@pb1.pair.com> To: internals@lists.php.net References: <20160118131911.DA1832607EC@dd15934.kasserver.com> Date: Tue, 19 Jan 2016 01:35:10 +0000 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:42.0) Gecko/20100101 Firefox/42.0 SeaMonkey/2.39 MIME-Version: 1.0 In-Reply-To: <20160118131911.DA1832607EC@dd15934.kasserver.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 90.212.141.145 Subject: Re: [PHP-DEV] [RFC] Allow specifying keys in list() From: ajf@ajf.me (Andrea Faulds) Hi Thomas, Thomas Bley wrote: > What about using objects with list()? > > class Point { > public function __construct($x, $y) { > $this->x = $x; > $this->y = $y; > } > } > > $point = new Point(21, 42); > list('x' => $x, 'y' => $y) = $point; You can't do `$x = $point['x'];`, so `list("x" => $x) = $point;` won't work either. If you want list() support, implement ArrayAccess. We could potentially add some extension to list() for object destructuring, but I'm not sure I'd be happy with that, as list() has thus far been an array-only thing. If we ever add object literals, then we could do object destructuring with a symmetrical syntax. Thanks. -- Andrea Faulds https://ajf.me/