Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61231 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78741 invoked from network); 14 Jul 2012 17:31:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2012 17:31:36 -0000 Authentication-Results: pb1.pair.com header.from=glopes@nebm.ist.utl.pt; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=glopes@nebm.ist.utl.pt; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain nebm.ist.utl.pt from 193.136.128.21 cause and error) X-PHP-List-Original-Sender: glopes@nebm.ist.utl.pt X-Host-Fingerprint: 193.136.128.21 smtp1.ist.utl.pt Linux 2.6 Received: from [193.136.128.21] ([193.136.128.21:34055] helo=smtp1.ist.utl.pt) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8D/DD-20866-7FCA1005 for ; Sat, 14 Jul 2012 13:31:36 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp1.ist.utl.pt (Postfix) with ESMTP id 0718A700044D; Sat, 14 Jul 2012 18:31:33 +0100 (WEST) X-Virus-Scanned: by amavisd-new-2.6.4 (20090625) (Debian) at ist.utl.pt Received: from smtp1.ist.utl.pt ([127.0.0.1]) by localhost (smtp1.ist.utl.pt [127.0.0.1]) (amavisd-new, port 10025) with LMTP id MXdOZUzqB3hm; Sat, 14 Jul 2012 18:31:32 +0100 (WEST) Received: from mail2.ist.utl.pt (mail.ist.utl.pt [IPv6:2001:690:2100:1::8]) by smtp1.ist.utl.pt (Postfix) with ESMTP id A95E67000442; Sat, 14 Jul 2012 18:31:32 +0100 (WEST) Received: from damnation (unknown [IPv6:2001:470:94a2:4:2123:f30f:bbf8:6cd0]) (Authenticated sender: ist155741) by mail2.ist.utl.pt (Postfix) with ESMTPSA id 2CCE32001A44; Sat, 14 Jul 2012 18:31:30 +0100 (WEST) Content-Type: text/plain; charset=utf-8; format=flowed; delsp=yes To: "Anthony Ferrara" Cc: "Stas Malyshev" , "Brandon Wamboldt" , "Andrew Faulds" , internals References: <5000BF44.3080907@sugarcrm.com> Date: Sat, 14 Jul 2012 19:31:28 +0200 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Organization: =?utf-8?Q?N=C3=BAcleo_de_Eng=2E_Biom=C3=A9di?= =?utf-8?Q?ca_do_I=2ES=2ET=2E?= Message-ID: In-Reply-To: User-Agent: Opera Mail/12.50 (Linux) Subject: Re: [PHP-DEV] Re: array_last_key() function From: glopes@nebm.ist.utl.pt ("Gustavo Lopes") Em Sat, 14 Jul 2012 19:13:32 +0200, Anthony Ferrara escreveu: > Why is the last key special? Why not a function to get the first or the >> penultimate key? >> > > How would such a function look? I think you've misread my statement. I was not suggesting a function that would get an arbitrary key. I was asking what was special about the last key that would merit a dedicated function. The underlying position was that there was nothing special about them (but see below), and a dedicated function function was not warranted. >> Of course, there is one aspect where the first and last keys are special >> -- if you have some algorithm where you pop or shift the array >> successively. But in that case the argument about end() + key() having >> side effects is irrelevant because you are changing the array anyway. > > How are you changing the array by getting the last (or first) key in this > method? Could you elaborate on that? I'm afraid I also wasn't clear here. One certainly does not have to change the array to get the first or the last key. I was only stating that the circumstances where it would be important to get specifically the first or the last key are also those where you would want to have side effects. My argument was that getting specifically the first or last keys is only important if you are somehow traversing the array by removing the first or last elements specifically and that requires side effects*. *This statement requires some qualification. Of course, you don't need side effects to remove the last element; you could use array_slice() to implement a sort of array_rest() or array_most() that would remove the first or the last element. But 1) it is not efficient to use these patterns in PHP and 2) since you are anyway copying parts you the array, it is not a problem to change those copies. -- Gustavo Lopes