Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89959 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 89326 invoked from network); 1 Jan 2016 21:55:08 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jan 2016 21:55:08 -0000 Authentication-Results: pb1.pair.com smtp.mail=dragoonis@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dragoonis@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.53 as permitted sender) X-PHP-List-Original-Sender: dragoonis@gmail.com X-Host-Fingerprint: 74.125.82.53 mail-wm0-f53.google.com Received: from [74.125.82.53] ([74.125.82.53:38653] helo=mail-wm0-f53.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5A/13-06661-AB5F6865 for ; Fri, 01 Jan 2016 16:55:07 -0500 Received: by mail-wm0-f53.google.com with SMTP id b14so116196759wmb.1 for ; Fri, 01 Jan 2016 13:55:06 -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=4rlYzBl8KDy5A/ZOGtyS8WELn8Ftm/m+QFVeaZAdSC4=; b=WnHcrApR5U3w54hEQnkJpH3HdQvb8joKB6UGAnsyVoiQUd+lsI1AQe3Pp/9wFwVG4x 73G5z+awJk0Tmcg5a4DWSKG6jJ5dDWxKBUztrrieCvghfUUyDswvP2QOhyf8BQOH2uLM xAfmsZd6j+DUY734akwlinDsG4K/npVJwUU8RAqzY5E8OKc1ZSkoCoi/OayAoog8zZh6 GCbiAIBrOnoLNXiihEfknMPsyHa0itQW8+YDlMBbjCKgY2VEToSbITaShbynAc0XyXqX EQQS2B1doacMYpRDlY4oa1TWzt47O9Y2Gm5wKovq5O20oyFngUz05vzAknJAHfZuyee3 7OpA== MIME-Version: 1.0 X-Received: by 10.194.117.68 with SMTP id kc4mr39347526wjb.111.1451685303879; Fri, 01 Jan 2016 13:55:03 -0800 (PST) Received: by 10.27.218.81 with HTTP; Fri, 1 Jan 2016 13:55:03 -0800 (PST) In-Reply-To: <86A2B77B-3DCA-420A-A044-C68158E6C4C4@zort.net> References: <070A1824-9ED7-4863-92AB-A4366AB92C98@zort.net> <86A2B77B-3DCA-420A-A044-C68158E6C4C4@zort.net> Date: Fri, 1 Jan 2016 21:55:03 +0000 Message-ID: To: John Bafford Cc: bishop@php.net, PHP internals Content-Type: multipart/alternative; boundary=001a1130c8d0dd120b05284cd2c0 Subject: Re: [PHP-DEV] [RFC] array_key_(first|last|index) functions proposal From: dragoonis@gmail.com (Paul Dragoonis) --001a1130c8d0dd120b05284cd2c0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi John, Thanks for submitting the RFC. It just has one piece of something that I feel needs a bit of refinement. The balance of the $key and the $val is out of sync, with one param being by-val and one by-ref. You could simplify the function to remove the &$val altogether, since the function name is about getting the key. Less is more here. I know you pointed out examples of other unusual functions, but we must live with those things historically for BC reasons. Given the opportunity to get it right I'd like to propose removal of &$val so the function does what its name says. Thus it would look like this: $val =3D $array[array_key_last($array)]; Many thanks, Paul On Fri, Jan 1, 2016 at 9:51 PM, John Bafford wrote: > > > On Jan 1, 2016, at 16:38, Bishop Bettini wrote: > > > > On Fri, Jan 1, 2016 at 3:44 PM, John Bafford wrote: > > Happy New Year, everyone! > > > > I=E2=80=99d like to present the first new PHP RFC for this year, a prop= osal to > add functions to easily get the first, last, or an arbitrary key (and > value) by index from an array, taking advantage of PHP=E2=80=99s property= that > arrays are ordered maps. > > > > Thanks for submitting this RFC! I am +1, with one quibble: obtaining > the value by reference seems non-sequitur to the function itself and PHP = in > general. IOW, this seems more PHPesque to me: > > > > // get the next to last value > > $key =3D array_key_index($arr, -2); > > $val =3D $arr[$key]; > > > > Sincerely, > > bishop > > While relatively rare for PHP, these aren't the only functions that have > an optional second return value by reference. (preg_match, preg_replace, > str_replace, among others.) > > I agree that that=E2=80=99s a bit unusual in terms of PHP, but, if you ac= tually > need both the key and the value, this way you can do it in one call, rath= er > than having to access the array and pull the value out of it separately. > The C code already has a reference to the hashtable bucket, so returning > the value if it=E2=80=99s needed is trivial. > > -John > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > --001a1130c8d0dd120b05284cd2c0--