Re: [discussion] add array_usearch()
Hi,
some thoughts on your discussion:
Am 07.02.2014 07:55 schrieb "Tjerk Meesters" <[email protected]>:
>
> That was my first attempt actually; if the first argument is a closure,
use
> that as the search callback. A few problems with that:
> 1) You can't use other types of callback, e.g. string or array.
For that (and possibly other uses), it would be good to have a
cast-to-closure:
$foo = (Closure) 'is_numeric';
$bar = (Closure) [ $that, 'method' ];
That might sometimes even save some work, when the implementation attempts
to extract the signature of the thing that is to be cast to make a proper
signature for the generated closure. If the callable is then used several
times later (callback in a loop) the callable-as-array-or-string-lookup
would no longer sit in the middle of the loop.
> 2) [bc] You can't search through an array of closures.
That's not good. Could be worked around by using a closure that compares to
the needle closure, but it would still be a BC break.
Code that might be affected would be some kind of registry for lists of
callbacks that, upon insert, wants to check that the thing to be inserted
isn't there already. I wrote something like that two weeks ago,
incidentally :)
In the long run, using an is-closure (not is-callable) vs. is-string branch
in various callback-taking functions, would make for cleaner code, compared
to sprinkling bitmask flag arguments with a DO_IT_CALLBACK_STYLE flag.
best regards
Patrick
Thread (11 messages)