Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array

From: Date: Sun, 20 Oct 2024 20:21:49 +0000
Subject: Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array
References: 1  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Sun, Oct 20, 2024, at 12:42 PM, Gina P. Banyard 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

Like others, I'm skeptical of the behavior here not being all that clear.

What several other languages do, and what I have in the plan for collections if/when they ever
happen, is sort() sorts in place, while sorted() returns a new value.  There's similarly
reverse() (in place) and reversed() (new value returned).  

*sorted($arr) seems like it would be a lot less confusing, and consistent with what other languages
(and hopefully future PHP) do.  (I don't know what that means for array_walk(), but I
don't know what that would even return anyway.)

--Larry Garfield


Thread (24 messages)

« previous php.internals (#125812) next »