Re: [RFC proposal] Syntactic sugar for array push()
| From: | Dušan Kreheľ | Date: | Fri, 12 Sep 2025 19:02:04 +0000 |
| Subject: | Re: [RFC proposal] Syntactic sugar for array push() | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-128686@lists.php.net to get a copy of this message | ||
[+] 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.
pi 12. 9. 2025 o 16:23 Rob Landers <rob@bottled.codes> napísal(a):
>
>
> On Fri, Sep 12, 2025, at 13:06, Dušan Kreheľ wrote:
>
> Hm, I didn't know about $array[] = 1;.
>
> It would make sense if it were: $a[+] for push() and $a[-] for pop().
>
> pi 12. 9. 2025 o 12:35 Ken Guest <kguest@php.net> napísal(a):
>
> But we already have $array[] = 1; - are you unaware of it or is there
> some other benefit to what you are suggesting?
>
> What might interest people would be a syntactic sugar/shorthand for
> array_pop but I have no idea what that might look like.
>
> On Fri, 12 Sept 2025 at 11:21, Dušan Kreheľ <dusankrehel@gmail.com> wrote:
>
> A proposal to add syntactic sugar for array_push() in PHP.
>
> Syntax:
> // now
> array_push($array, 1);
>
> // new syntax
>
> $array[+]=1;
>
>
> Dušan Kreheľ
>
>
>
> --
> http://about.me/kenguest/
>
>
> I'd personally rather have sugar for array_unshift and array_shift, than
> pop and push.
>
> — Rob
>