Re: [discussion] add array_usearch()

From: Date: Fri, 07 Feb 2014 07:09:51 +0000
Subject: Re: [discussion] add array_usearch()
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-72365@lists.php.net to get a copy of this message
Hi, some thoughts on your discussion: Am 07.02.2014 07:55 schrieb "Tjerk Meesters" <tjerk.meesters@gmail.com>: > > 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

« previous php.internals (#72365) next »