Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102758 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29902 invoked from network); 11 Jul 2018 15:19:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 15:19:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=bjorn.x.larsson@telia.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bjorn.x.larsson@telia.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain telia.com designates 81.236.60.155 as permitted sender) X-PHP-List-Original-Sender: bjorn.x.larsson@telia.com X-Host-Fingerprint: 81.236.60.155 v-smtpout2.han.skanova.net Received: from [81.236.60.155] ([81.236.60.155:43500] helo=v-smtpout2.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 20/97-15421-2EF164B5 for ; Wed, 11 Jul 2018 11:19:00 -0400 Received: from [192.168.8.9] ([94.254.95.82]) by cmsmtp with ESMTPA id dGtJfExxqUtqsdGtJfPCNJ; Wed, 11 Jul 2018 17:18:55 +0200 To: Levi Morrison , "Woortmann, Enno" Cc: =?UTF-8?Q?Pedro_Magalh=c3=a3es?= , CHU Zhaowei , PHP internals References: Message-ID: <13b4eb91-6566-3724-d45d-aa63254e1f58@telia.com> Date: Wed, 11 Jul 2018 17:19:01 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB X-CMAE-Envelope: MS4wfKl08tXaBdglbOu5fnq7UQuC7E5+KIB5PtEcHFk+gatKAIiNnmpz1xOD5ZzoQegQnEezjX2hbapnx3YU6WVXEMFxWgTYIoi00Rk5FDvYX+BFiDME40UK Eta57lzqg7Ek4WRSa3XeMaTRFarGPEBdniMAWmLMgGbY7iE6pFJkSZnndgl3jbi7qBhb+UuoMGJ3jk53rpmhe235ywOSjIgxjd2X6JLdHhv/Ao1WUSkyWeYJ raOMIIgZzl2KeMXvZwW3UB2tIhl0VPFUAA3hHgBkTvGOyBmtk1edl5leuVVihJPN Subject: Re: [PHP-DEV] Re:[PHP-DEV] [VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last() From: bjorn.x.larsson@telia.com (=?UTF-8?Q?Bj=c3=b6rn_Larsson?=) Den 2018-07-11 kl. 02:41, skrev Levi Morrison: > On Tue, Jul 10, 2018 at 12:59 PM Pedro Magalhães wrote: >> On Mon, Jul 9, 2018 at 6:31 PM CHU Zhaowei wrote: >> >>> I don't think we have an agreement on dealing with non-existing value, and >>> the way this RFC proposed, just returning null without any notice/warning, >>> is wrong IMO. I know we already do this in other array_* functions, but we >>> cannot keep making mistakes just because we already made same mistake. >>> >> I voted no for the same reason. I'd even say that introducing a new array_ >> function that still accepts non arrays just to return null with a warning >> doesn't make sense at this point. >> >> With that said, I'd gladly vote yes if there would be a way to distinguish >> array_value_first([]) from array_value_first([0 => null]). >> >> Regards, >> Pedro > To safely use it a call to empty or count or something needs to happen: > > if (!empty($array)) { > $value = array_value_first($array); > // do something with $value > } > > This is okay, but not great. Compare that to the design that returns a > tuple though: > > if ([$_, $value] = array_first($array)) { > // do something with $value > } > > People who argue against the tuple because they don't like the design > need to consider the bigger picture. The tuple way is less code, > serves more use cases with fewer functions, and I even [implemented > it][1]. If the array destructuring behavior seems unclear we can > simply put an example in the manual pages for these functions -- > problem solved. > > This is not how RFC feedback should be handled. I hope more people > vote no so we can reject this do it properly. > I do like this approach with two functions array_first & array_last returning a tuple. However, voting is  underway and it looks like it will pass. I wonder what the RFC author (Enno W) thinks about that approach? r//Björn Larsson