Re: RFC karma request: array_partition()

From: Date: Sat, 24 Oct 2026 04:46:28 +0000
Subject: Re: RFC karma request: array_partition()
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-132911@lists.php.net to get a copy of this message
On 2026-10-24 12:16, mickmackusa wrote:
Hi Ayoub, - It feels unintuitive that true callback outcomes map to the 0 key and false outcomes map to 1. I'm also in support, and this would have been my only observation: my partition functions also map passes and rejects to true and false respectively (so the result is a mapping from booleans to array values).
If that mapping were retained, it could be documented in code as [true => $passed, false => $rejected] = array_partition(...); or $adult_tested = array_partition(...); $adults = $adult_tested[true]; $minors = $adult_tested[false]; I would also prefer the callback parameter to be named $predicate, to emphasise that it is supposed to return a boolean. $callback doesn't convey as much about what it's for - the same name is used, for example, in usort(), where it's a comparator. It didn't matter until named parameters became a thing.

« previous php.internals (#132911) next »