Re: [RFC proposal] Syntactic sugar for array push()
| From: | Rowan Tommins [IMSoP] | Date: | Sat, 13 Sep 2025 10:21:35 +0000 |
| Subject: | Re: [RFC proposal] Syntactic sugar for array push() | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128697@lists.php.net to get a copy of this message | ||
On 12 September 2025 20:02:04 BST, "Dušan Kreheľ" <dusankrehel@gmail.com> wrote:
>[+] array_push
>[-] array_pop
>[-<] array_shift
>
>array_unshift() is a special case of array_merge(), so it would then need
>syntactic sugar for merging arrays, or rather a reserved merge.
array_unshift is no more a special case of array_merge than array_push, particularly in the
single-element case we're talking about here - it's really just the same operation at the
other end of the array.
Since we have an extremely well-established array_push shorthand, so don't need a new one, we
could perhaps have "<" for "at start", and "-" for "pop":
$foo[] = $toPush;
$popped = $foo[-];
$foo[<] = $toUnshift;
$shifted = $foo[-<];
I'm not totally convinced it's necessary, but I don't completely hate it.
P.S. Quick reminder to all contributors on this thread that the policy here is to reply *below* the
relevant quoted text, editing as necessary; do not reply *above* the entire quoted thread.
Rowan Tommins
[IMSoP]