Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67722 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67766 invoked from network); 18 Jun 2013 16:38:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jun 2013 16:38:30 -0000 Authentication-Results: pb1.pair.com header.from=theanomaly.is@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=theanomaly.is@gmail.com; spf=pass; 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:57027] helo=mail-wg0-f49.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 04/50-00171-40D80C15 for ; Tue, 18 Jun 2013 12:38:29 -0400 Received: by mail-wg0-f49.google.com with SMTP id a12so3734943wgh.16 for ; Tue, 18 Jun 2013 09:38:25 -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=kzojXrAt80PvVXPi+D9kHBXH5uQX+mO/LQcs1Pc5c9M=; b=RgW4L1a6i2/luELGuj7VBpZepF6X39E7jLPMsNxztXpuHsit9fq1Hbf6n4SwPKPoa6 6PbNOUzTGeLl+gxM08XbjhFwic9Kgw1Hc4ObYoxnBR3O06JjCVWVMBRRpDVEV3dFtlm+ d5ly5IKLNgyX6Ewd9Zto6ougOIuHKY3VJ3XrimkBRx3oKzI6Kf3FpAV1nNAfHslu3xqO HEBdD0hqAaUWxn1gDxI0U4Q6+W9FbLAp7GURCZwLArvRKS/xlrLJv6O3xjEhyhNWEMKe wPXFP3Od6pUPdzWx1IogsuvbDSILCJNTv/N5LIRdgpy0x8JQW8RyBMAMwVe8qxM+rifg +2vg== MIME-Version: 1.0 X-Received: by 10.180.11.166 with SMTP id r6mr8097189wib.45.1371573505189; Tue, 18 Jun 2013 09:38:25 -0700 (PDT) Received: by 10.227.156.201 with HTTP; Tue, 18 Jun 2013 09:38:25 -0700 (PDT) In-Reply-To: References: Date: Tue, 18 Jun 2013 12:38:25 -0400 Message-ID: To: Leigh Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a11c248f08f728404df705765 Subject: Re: [PHP-DEV] PR 287 - added use_keys argument to array_filter() [Discussion] From: theanomaly.is@gmail.com (Sherif Ramadan) --001a11c248f08f728404df705765 Content-Type: text/plain; charset=ISO-8859-1 On Tue, Jun 18, 2013 at 11:27 AM, Leigh wrote: > On 18 June 2013 00:20, Sherif Ramadan wrote: > >> I'm starting up a thread for discussion on Pull Request 287 >> https://github.com/php/php-src/pull/287 (allowing array keys to be passed >> to the callback function of array_filter through a third optional boolean >> argument). >> > > Why not use array_filter_keys? > > That actually isn't a bad idea. I would consider going that route if this patch presents any real world problems that could be better solved with introducing a new function. I just don't see any reason for a new function now given that this patch does not present any BC and can still solve the same problem without adding a new function. > There are many other array functions that work with keys using this naming > pattern. This would make it clearer in the code what is being filtered, and > no need for the additional parameter. > > The problem with having one callback for just the keys and another for the array elements is that you're stuck in a situation where you can't possibly use both. We have that problem with array sort functions that allow a user defined callback. For example, we have usort and uksort, but there is no sort function that can offer both. It's plausible that a user may be relying on both in certain cases (for a example a map of maps). > In this case I think I would still prefer it if the callback took a single > parameter. Values can still be easily looked up with $array[$key] in user > defined callbacks, but all of the built-in functions that take a single > parameter are still available to use. > I would like to solve the problem without introducing new problems. If I can do that we get PHP to take a step forward and not a step side-ways. --001a11c248f08f728404df705765--