Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67732 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 99654 invoked from network); 18 Jun 2013 23:15:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Jun 2013 23:15:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=tjerk.meesters@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=tjerk.meesters@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.160.45 as permitted sender) X-PHP-List-Original-Sender: tjerk.meesters@gmail.com X-Host-Fingerprint: 209.85.160.45 mail-pb0-f45.google.com Received: from [209.85.160.45] ([209.85.160.45:36672] helo=mail-pb0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C2/61-27508-92AE0C15 for ; Tue, 18 Jun 2013 19:15:54 -0400 Received: by mail-pb0-f45.google.com with SMTP id mc8so4397232pbc.18 for ; Tue, 18 Jun 2013 16:15:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=references:mime-version:in-reply-to:content-type :content-transfer-encoding:message-id:cc:x-mailer:from:subject:date :to; bh=YhsNVjylibHOtBVTST8g4W9suQ1ZqRTugL33Qwl1f+w=; b=IG9Z9ORx+28JUH63plQ0ZQJjnyegC7y4HGIrTnkrCU5TgbToHQaK0vFa64MWKyLzGu P2au0rMcylbfq0jyB5It/9eC/p13+cUE4HL6jKE2eiRX90+d0cp6M+wXnUTCSj+pprh0 EaMMT3rFfSInE2V7LlEpO79KER77xicbGrKhZvNxD8FxXXWZKO14ZtwV8aX5hP6Ivrat Mpw0KnsS5Pn3k3SIRjbnBq8T7t4HA9dXR+omkno+/ei47I86uNn6hPvMWzStxH+kDB60 B0rQjcEPd3U4HcM3VbDlwv3TvnLkvZHTvz55J1ptwHyoIfD9MR0/J5MzLxpfu0AP9Cp9 +ajw== X-Received: by 10.68.164.196 with SMTP id ys4mr42810pbb.170.1371597350260; Tue, 18 Jun 2013 16:15:50 -0700 (PDT) Received: from [192.168.1.104] (bb42-60-19-235.singnet.com.sg. [42.60.19.235]) by mx.google.com with ESMTPSA id ve3sm6507664pbc.14.2013.06.18.16.15.47 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Jun 2013 16:15:49 -0700 (PDT) References: Mime-Version: 1.0 (1.0) In-Reply-To: Content-Type: multipart/alternative; boundary=Apple-Mail-9EF60438-D2D3-4BFE-B312-C32754CF5569 Content-Transfer-Encoding: 7bit Message-ID: <13848974-B5E7-4044-9F04-C4EB15E09E9C@gmail.com> Cc: Sherif Ramadan , internals , Tjerk Anne Meesters , Levi Morrison X-Mailer: iPhone Mail (10B329) Date: Wed, 19 Jun 2013 07:15:45 +0800 To: Patrick Schaaf Subject: Re: [PHP-DEV] PR 287 - added use_keys argument to array_filter() [Discussion] From: tjerk.meesters@gmail.com (Tjerk Meesters) --Apple-Mail-9EF60438-D2D3-4BFE-B312-C32754CF5569 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable On 19 Jun, 2013, at 1:04 AM, Patrick Schaaf wrote: >=20 > > 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. Tha= t's > > BC and performance loss that's simply unacceptable, so defaulting the > > behavior to pass the key is simply out of the question. >=20 > Existing code won't pass that third, true, argument to array_filter(), and= thus will not break. >=20 > Nevertheless, I'd say go with a new array_filter_key() function, because t= hat permits using existing one-parameter functions like that strlen as a cal= lback, instead of forcing two-parameter callback functions. >=20 I've mirrored the behaviour of this feature from JavaScript as much as possi= ble (but obviously without passing the array itself as the third argument). A= s such I don't feel there's a need to introduce yet another function just so= that the key is passed as the first argument. And to use both key and value= forces the developer to use closures instead of just any callback unless th= is means the second argument passed to the callback is the array :) > 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_FIL= TER_VAL - only one of them set calls with a single argument, both set call w= ith two arguments. >=20 I see some potential here, albeit a bit more magical :) Let's see how the di= scussion progresses.=20 > best regards > Patrick --Apple-Mail-9EF60438-D2D3-4BFE-B312-C32754CF5569--