Re: [RFC] Allow specifying keys in list()
| From: | Andrea Faulds | Date: | Tue, 19 Jan 2016 01:35:10 +0000 |
| Subject: | Re: [RFC] Allow specifying keys in list() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-90706@lists.php.net to get a copy of this message | ||
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/