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

From: Date: Mon, 21 Oct 2024 20:41:53 +0000
Subject: Re: [RFC] Change behaviour of array sort functions to return a copy of the sorted array
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On Tue, 22 Oct 2024, 02:30 Valentin Udaltsov, <[email protected]>
wrote:

>
> What if instead of this proposal we reimplement all of the array
> functions in a different namespace and fix a lot of other problems and
> inconsistencies?
>
> Array\map(iterable $iterable, callable $mapper): array
> Array\sort(iterable $iterable, int $flags = SORT_REGULAR): array
> ...
>
> --
> Valentin


Getting off-topic here, but array_map()'s parameter order matters.  Because
it can receive one or more arrays, the callback should be the first
parameter to afford, say, spreading the rows of a multidimensional array
during transposition.  The same "spreadability" logic should apply to
array_*diff*(), array_*intersect*(), and array_multisort().  If we were
going for consistency, always write callbacks as the first parameter for
any function that has one. In other words, parameters which can be repeated
more than once must be list as the last parameter.

It is clear that this RFC is seeking success by making the smallest
possible, very practical change. While it is healthy to explore deviations,
I like the RFC on it's own because it makes PHP more adaptable to writing
elegant code with fewer temporary variables.

Mick

>


Thread (24 messages)

« previous php.internals (#125827) next »