Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:96669 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73028 invoked from network); 30 Oct 2016 23:33:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 30 Oct 2016 23:33:11 -0000 Authentication-Results: pb1.pair.com smtp.mail=php@fleshgrinder.com; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=php@fleshgrinder.com; sender-id=unknown Received-SPF: error (pb1.pair.com: domain fleshgrinder.com from 77.244.243.85 cause and error) X-PHP-List-Original-Sender: php@fleshgrinder.com X-Host-Fingerprint: 77.244.243.85 mx104.easyname.com Received: from [77.244.243.85] ([77.244.243.85:56239] helo=mx206.easyname.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 00/99-25911-53386185 for ; Sun, 30 Oct 2016 18:33:10 -0500 Received: from cable-81-173-132-21.netcologne.de ([81.173.132.21] helo=[192.168.178.20]) by mx.easyname.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1c0zb8-0007Y4-6W; Sun, 30 Oct 2016 23:33:06 +0000 Reply-To: internals@lists.php.net 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> To: Yasuo Ohgaki , "internals@lists.php.net" , Rowan Collins Message-ID: <1645f932-f203-56fa-aa0f-f1f20b7c57a5@fleshgrinder.com> Date: Mon, 31 Oct 2016 00:32:50 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Allow Iterator to be used with current, next, reset, key functions From: php@fleshgrinder.com (Fleshgrinder) On 10/31/2016 12:25 AM, Yasuo Ohgaki wrote: > It depends. Defining specific functions for a task could be bad design > also. We do design basic functions with flags usually, too. > I know that we have lots of them but they almost always end up in hard to read and understand I-can-do-everything functions and their implementation is also cluttered with branching. On 10/31/2016 12:25 AM, Yasuo Ohgaki wrote: > That said, dedicated functions for getting first/last key/value sounds > good to me. > > A agree. That's the reason why I state return value is problem. However, > > if (empty($arr)) { > // Do something > } else { > $first = array_first($arr); > } > > shouldn't be difficult. > > We should raise error for nonsense usage. Programmers have to check > empty()/isset() all the time anyway. > I am an assert programmer, hence, I have no problem with an error in such a case if others are fine with it. @Rowan absolutely right, hence, if really needed: ``` function array_shift_key(array $array); function array_pop_key(array $array); ``` -- Richard "Fleshgrinder" Fussenegger