Re: [RFC] Short Array Variable Shorthand
| From: | Christian Schneider | Date: | Wed, 30 Sep 2026 12:01:18 +0000 |
| Subject: | Re: [RFC] Short Array Variable Shorthand | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-132712@lists.php.net to get a copy of this message | ||
Am 29.09.2026 um 19:44 schrieb Weilin Du <weilin-du@qq.com>:
> Today, I want to announce my second RFC to php 8.7
> https://wiki.php.net/rfc/array_shorthand
>
> This RFC brings a IMO useful syntactic sugar to array's
> construction and destruction. I hope you'all find this
> interesting! To be short:
>
> ```
> $point = [:$x, :$y, :$z]; // ['x' -> $x, 'y' -> $y, 'z'
> -> $z]
> [:$x, :$y, :$z] = $point; // reverse.
> ```
We have been using a local patch for this short-hand syntax for many years and are very happy as for
our coding style this comes up quite often.
I prefer the original :$foo instead of =$foo even though there is a minor clash with the ternary
operator but to be honest I would find
[ $bool ? =$foo : =$bar]
to return either an array with the key 'foo' or 'bar' not useful enough and
would rather use
$bool ? [:$foo] : [:$bar]
So you have a +1 from me but I would strongly prefer : instead of =,
- Chris