Hi folks!
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 also support the foreach syntax ofc, see examples
in the RFC.
Same feature has been implemented in perl. And 13
years ago the named argument RFC have already
list this as part of the future scope 1
Some may ask why don't you propose this for all
functions but just for the [] syntax in arrays? Well,
sadly I don't have enough time and energy to put
in php now (I am unfunded) so I will leave it for others
if they want in the future.
Again I hope you'all find this useful and interesting :)
Thank you,
Weilin Du
Hi,
Some amendment have been added after this email.
We are using the = char instead of :
$point = [=$x, =$y];
And we are supporting array() and list() for this RFC now,
so not only [].
See the RFC for reasons. Discussions have happened in
the official phpc's discord server and thanks Tim Düsterhus
for the ideas.
This RFC is still in a very early stage. So there can be vagueness
and obvious issues. If there is, please point out.
Thanks,
Weilin Du