Re: PR 287 - added use_keys argument to array_filter() [Discussion]

From: Date: Tue, 18 Jun 2013 16:42:31 +0000
Subject: Re: PR 287 - added use_keys argument to array_filter() [Discussion]
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-67724@lists.php.net to get a copy of this message
On Tue, Jun 18, 2013 at 11:37 AM, Tjerk Anne Meesters <datibbaw@php.net>wrote: > > > > The danger actually lurks in the cases whereby the second argument is > accepted and with that (sometimes radically) change the semantics of the > function; in fact, quite a few internal functions have this kind of > switch-by-argument behaviour, such as "array_keys" to randomly name one. > And admittedly, this function when my PR goes through ;-) > > > That is a worse outcome, sure, but there is still danger in the former scenario given that defaulting the callback to take two arguments causes the wrong result: var_dump(array_filter(['foo', '', 'bar'], 'strlen', true)); Warning: strlen() expects exactly 1 parameter, 2 given in - on line 1 Warning: strlen() expects exactly 1 parameter, 2 given in - on line 1 Warning: strlen() expects exactly 1 parameter, 2 given in - on line 1 array(0) { } Not only do we trigger the error handler (a large enough array causes a performance issue), but we also get back an empty array as a result. That's BC and performance loss that's simply unacceptable, so defaulting the behavior to pass the key is simply out of the question. > > -- > -- > Tjerk >

« previous php.internals (#67724) next »