Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array
On Mon, Oct 21, 2024 at 3:44 AM Gina P. Banyard <[email protected]> wrote:
> Hello internals,
>
> I would like to propose a short RFC to make the return value of the sort()
> and similar functions more useful:
> https://wiki.php.net/rfc/array-sort-return-array
>
> I intend for the discussion to last 2 weeks and then open the vote.
>
> Best regards,
>
> Gina P. Banyard
>
I like this RFC because I have a distaste for any function/method that
always returns a single value -- the return value indicates nothing usable.
I also find that I prefer to avoid array_walk() because I can't elegantly
nest it in other function calls or return/print the traversed data.
Might the transition be simpler if the naming convention is standardized to
have array_ meaning "returns the input [sorted|shuffled|traversed] array"
and without the prefix means "modify by reference"?
That naming convention will not look absurd among other native array_
functions and prefix-trimmed functions will afford developers to continue
using the original modify by reference behavior (if they have performance
or memory reasons).
| returns copy of array | by reference |
| ---------------------- |---------------- |
| array_sort() | sort() |
| array_rsort() | rsort() |
| array_asort() | asort() |
| array_arsort() | arsort() |
| array_ksort() | ksort() |
| array_krsort() | krsort() |
| array_natsort() | natsort() |
| array_natcasesort() | natcasesort() |
| array_usort() | usort() |
| array_uasort() | uasort() |
| array_uksort() | uksort() |
| array_multisort() | multisort() |
| array_shuffle() | shuffle() |
| array_walk() | walk() |
| array_walk_recursive() | walk_recursive() |
Good luck regardless,
mickmackusa
Thread (24 messages)