Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96665 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 66606 invoked from network); 30 Oct 2016 23:00:12 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Oct 2016 23:00:12 -0000 Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:54800] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 1F/38-25911-77B76185 for ; Sun, 30 Oct 2016 18:00:11 -0500 Received: (qmail 19476 invoked by uid 89); 30 Oct 2016 23:00:00 -0000 Received: from unknown (HELO mail-wm0-f42.google.com) (yohgaki@ohgaki.net@74.125.82.42) by 0 with ESMTPA; 30 Oct 2016 23:00:00 -0000 Received: by mail-wm0-f42.google.com with SMTP id p190so116865095wmp.1 for ; Sun, 30 Oct 2016 15:59:59 -0700 (PDT) X-Gm-Message-State: ABUngvf4p/SocKNPvDPLEcYH3aans6dkEtog7djf8Rvvew+g17J84M/IaPWHj6OAt6+NpS3AK3h61AcvMTjTzA== X-Received: by 10.194.115.135 with SMTP id jo7mr19890733wjb.21.1477868393093; Sun, 30 Oct 2016 15:59:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.194.205.42 with HTTP; Sun, 30 Oct 2016 15:59:12 -0700 (PDT) In-Reply-To: <35e0c893-435e-d5da-58be-4f63796775b4@fleshgrinder.com> References: <44244cfd-c8ad-e0a9-4e70-380a8a8c940c@syberisle.net> <01f2f3da-592b-fd23-709d-ad620422f56d@fleshgrinder.com> <402447f2-6007-95c4-6b1d-2bbb30dfdd1d@fleshgrinder.com> <35e0c893-435e-d5da-58be-4f63796775b4@fleshgrinder.com> Date: Mon, 31 Oct 2016 07:59:12 +0900 X-Gmail-Original-Message-ID: Message-ID: To: "internals@lists.php.net" Cc: Rasmus Schultz , Levi Morrison Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] Allow Iterator to be used with current, next, reset, key functions From: yohgaki@ohgaki.net (Yasuo Ohgaki) Hi all, On Mon, Oct 31, 2016 at 4:08 AM, Fleshgrinder wrote: > On 10/30/2016 4:08 PM, Rasmus Schultz wrote: >> But either way, I think I'm changing my mind about this one. >> >> And if the these functions support only arrays, then also the names >> should probably be array_first() and array_last() for consistency with >> other array-only functions. >> >> Perhaps better to make people be explicit, rather than trying to hide >> side-effects to achieve shorter syntax... >> > > +1 +1 There should be delete option. It's more useful if there is this option. mixed array_first(array $arr [,bool $get_key = FALSE [, bool $remove_entry=FALSE]]); mixed array_last(array $arr [,bool $get_key = FALSE [, bool $remove_entry=FALSE]]); Problem with this is error condition. When array is empty, what should be returned from these with default option? Returning NULL for empty array would be enough. IMO. On Mon, Oct 31, 2016 at 1:52 AM, Levi Morrison wrote: > To clarify, do you use the return value of these functions or rely on > the IAP moving to also get the key? Depends on code, but I usually use them just to get value of head/tail element. It could be array_slice/splice, so I don't have much problem with removing internal array position pointer. However, I still need current() or each() to get value from returned array. This applies to array_first/last($arr, TRUE); Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net