Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67727 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 76926 invoked from network); 18 Jun 2013 17:24:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jun 2013 17:24:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.49 as permitted sender) X-PHP-List-Original-Sender: theanomaly.is@gmail.com X-Host-Fingerprint: 74.125.82.49 mail-wg0-f49.google.com Received: from [74.125.82.49] ([74.125.82.49:51646] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 0F/52-00171-3C790C15 for ; Tue, 18 Jun 2013 13:24:21 -0400 Received: by mail-wg0-f49.google.com with SMTP id a12so3638266wgh.28 for ; Tue, 18 Jun 2013 10:24:15 -0700 (PDT) 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=cwz5ZVvfj78KV6Pv8YmTkfardJDbhQT9ibbZWHMdJEc=; b=vXjC+LBBkIDRyZ2h662MPc4ZOpuq6DWLJXlIcf/7uA5zMFGeOemIniCYtspEHA8KtK bArjTHScpGbgpqW9R+fShim8QotgnwKXz1rIoBD4BRKIyOenm8erj5htXv1TGfGjYaiH JTnGOVQOE9h6OtrwvYKfGpxeQmW9A7TDItNzJRI04yl3aZfc+TdpC3KT6wXGRBoEBZNd jmsCzuRx85ejAAKXJGKhU8T8FvKjNOhLqMLVlRBxksCMmxuWXPfwTJ38nJKrtDXTkEyW mBAOrjVmNhvmF0nVzWU3u+cmIylXRspEI/XJTRW7JcEUm0tlvYmCV+wFH2hWFqVUR07t On3A== MIME-Version: 1.0 X-Received: by 10.194.119.195 with SMTP id kw3mr11458335wjb.64.1371576255740; Tue, 18 Jun 2013 10:24:15 -0700 (PDT) Received: by 10.227.156.201 with HTTP; Tue, 18 Jun 2013 10:24:15 -0700 (PDT) In-Reply-To: References: Date: Tue, 18 Jun 2013 13:24:15 -0400 Message-ID: To: Patrick Schaaf Cc: internals , Tjerk Anne Meesters , Levi Morrison Content-Type: multipart/alternative; boundary=089e0122894681842204df70fb92 Subject: Re: [PHP-DEV] PR 287 - added use_keys argument to array_filter() [Discussion] From: theanomaly.is@gmail.com (Sherif Ramadan) --089e0122894681842204df70fb92 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jun 18, 2013 at 1:04 PM, Patrick Schaaf wrote: > > > var_dump(array_filter(['foo', '', 'bar'], 'strlen', true)); > > > > Warning: strlen() expects exactly 1 parameter, 2 given in - on line 1 > > > > 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. > > Existing code won't pass that third, true, argument to array_filter(), and > thus will not break. > Of course not, the premise was that this would be the result if there was no third argument and the function would pass the key to the callback by default (in response to the comment above about removing the third argument). > Nevertheless, I'd say go with a new array_filter_key() function, because > that permits using existing one-parameter functions like that strlen as a > callback, instead of forcing two-parameter callback functions. > The current patch does not force the callback to take two arguments. By default the existing behavior is maintained since the third argument is false by default. I still don't hear a good argument for adding a new function. > Another alternative might be to go with a third argument to > array_filter(), but make that an integer with ORable constants > ARRAY_FILTER_KEY, ARRAY_FILTER_VAL - only one of them set calls with a > single argument, both set call with two arguments. > I would agree that this is a better solution than the existing patch allows since the function name does not suggest the filtering of a key or otherwise. In that case it would be easy to use bit-wise operators to get both the key and the element into the callback or just one or the other. The default would be ARRAY_FILTER_VAL, obviously. I suppose the order of the elements should remain $value, $key in the event of ARRAY_FILTER_KEY | ARRAY_FILTER_VAL. > best regards > Patrick > --089e0122894681842204df70fb92--