Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:72363 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46723 invoked from network); 7 Feb 2014 06:54:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 7 Feb 2014 06:54:56 -0000 Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.212.47 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.212.47 mail-vb0-f47.google.com Received: from [209.85.212.47] ([209.85.212.47:55871] helo=mail-vb0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 37/71-34013-F3384F25 for ; Fri, 07 Feb 2014 01:54:55 -0500 Received: by mail-vb0-f47.google.com with SMTP id p6so2261748vbe.6 for ; Thu, 06 Feb 2014 22:54:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=AZoBzNYV7C+kUEIMlmFvUSjuh3o4V/BDuSqGiN/hHXA=; b=vlpL/YlQ+77EoNOSmb5NyI+QC6RuSE8ol43DLFOUM5qUlIzNzW2ThQTywKdfcY9g6h 0qggnoSXxzDJBGpOgTq1kU+oPDNUUhmIpzSwZncc5sjBKe4ZYnK+oM8Afpd/MWNKgQDe 6c8H02LYZB2N6kGOqsh9hTg97wyxwNIdnQ5AAraeqU5iGuwiPTjucLn2BB4PmiJM5Xg6 d2doir2sTILbzB2HSSueGOis6C2OLTumIDpJZyChEBrgsZBBnhQ8LLNZothaVvHcG8h1 EbROf11AKKgPcht+8yr5a8GIqZ5OToFmf/u+q/YvCmwV9MTfZjURExMoXbbO//UNZEL7 kAkQ== MIME-Version: 1.0 X-Received: by 10.52.61.168 with SMTP id q8mr175590vdr.40.1391756092376; Thu, 06 Feb 2014 22:54:52 -0800 (PST) Received: by 10.58.133.229 with HTTP; Thu, 6 Feb 2014 22:54:52 -0800 (PST) In-Reply-To: References: Date: Fri, 7 Feb 2014 14:54:52 +0800 Message-ID: To: Yasuo Ohgaki Cc: Chris Wright , "Kingsquare.nl - Robin Speekenbrink" , PHP Internals Content-Type: multipart/alternative; boundary=001a1136b374800c1204f1cb7719 Subject: Re: [PHP-DEV] [discussion] add array_usearch() From: tjerk.meesters@gmail.com (Tjerk Meesters) --001a1136b374800c1204f1cb7719 Content-Type: text/plain; charset=ISO-8859-1 Hi, On Fri, Feb 7, 2014 at 2:36 PM, Yasuo Ohgaki wrote: > Hi all, > > On Fri, Feb 7, 2014 at 9:26 AM, Tjerk Meesters wrote: > >> I'm not wildly enthusiastic about another magic flags parameter, but it's >> an acceptable compromise for me. The slight advantage there is that >> `in_array()` would be bestowed upon the ability to take a callback >> function >> as well. Something like: >> >> if (in_array('is_numeric', $array, SEARCH_NEEDLE_IS_CALLBACK)) { ... } >> > > What we need is 'closure only callback'. > If we have it, then we don't have to worry about string callback functions. > > if (in_array(function($elem) {return is_numeric(strstr($elem));}, $array)) > { ... } > > Why don't we have 'closure' as signature? It can do more than calling > a function. > > bool in_array(closure $callback, array $ary); > > Cons would be we cannot search closures in $ary. > Is there any use of searching closure? > 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. 2) [bc] You can't search through an array of closures. 3) [minor] the $strict argument becomes ambiguous. The second problem can be mitigated by checking if $strict is given and `true`, but it becomes rather messy. > Regards, > > -- > Yasuo Ohgaki > yohgaki@ohgaki.net > > -- -- Tjerk --001a1136b374800c1204f1cb7719--