Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array
| From: | Gina P. Banyard | Date: | Mon, 21 Oct 2024 15:09:45 +0000 |
| Subject: | Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125825@lists.php.net to get a copy of this message | ||
On Monday, 21 October 2024 at 14:29, Ilija Tovilo <tovilo.ilija@gmail.com> wrote:
> Hi Gina
>
> On Mon, Oct 21, 2024 at 3:21 PM Gina P. Banyard internals@gpb.moe wrote:
>
> > On Sunday, 20 October 2024 at 18:42, Gina P. Banyard internals@gpb.moe wrote:
> >
> > > https://wiki.php.net/rfc/array-sort-return-array
> >
> > For an example, I'm going to pull out my solution to day 1 of the 2022 advents of
> > code:
> >
> >
> > https://github.com/Girgias/advent-of-code/blob/19283e1f5ef503c8a4478e58aaa57ff2fb7164c7/2022/01/puzzle.php#L25
> >
> > However, if the sort functions would return a useful value instead of
> >
true I could chain it together completely as follows:
> >
> > $top3 = array_slice(
> > rsort(
> > array_map(
> > 'array_sum',
> > array_map(
> > fn($v) => explode("\n", $v),
> > explode(
> > "\n\n",
> > $input
> > )
> > )
> > )
> > ),
> > 0,
> > length: 3
> > );
>
>
> Note that your example would still warn after this RFC, which is
> likely enough to deter people from writing code like this.
>
> https://3v4l.org/mRuoK
There is a very simple fix, which is to add the /** @prefer-ref $array */ doc comment to the stub of
the relevant functions.
Something that array_multisort() already does.
But thanks for reminding me how crap PHP references are :D
I'll amend the RFC soon to include this change as part of the proposal.
Best regards,
Gina P. Banyard