Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array
| From: | Bilge | Date: | Mon, 21 Oct 2024 00:18:04 +0000 |
| Subject: | Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125817@lists.php.net to get a copy of this message | ||
On 21/10/2024 00:16, mickmackusa wrote:
On Mon, Oct 21, 2024 at 3:44 AM Gina P. Banyard <internals@gpb.moe> wrote:I like this in theory, but array_multisort() and array_walk*() already broke your proposed convention:( Cheers, BilgeHello 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-arrayI intend for the discussion to last 2 weeks and then open the vote.Best regards,Gina P. BanyardI 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