Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102761 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 34998 invoked from network); 11 Jul 2018 15:53:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 15:53:09 -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:44016] helo=v-smtpout2.han.skanova.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 4A/88-15421-0E7264B5 for ; Wed, 11 Jul 2018 11:53:07 -0400 Received: from [192.168.8.9] ([94.254.95.82]) by cmsmtp with ESMTPA id dHQMfF3CrUtqsdHQMfPFcX; Wed, 11 Jul 2018 17:53:02 +0200 To: "Christoph M. Becker" Cc: Levi Morrison , "Woortmann, Enno" , =?UTF-8?Q?Pedro_Magalh=c3=a3es?= , CHU Zhaowei , PHP internals References: <13b4eb91-6566-3724-d45d-aa63254e1f58@telia.com> Message-ID: Date: Wed, 11 Jul 2018 17:53:09 +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: sv X-CMAE-Envelope: MS4wfMwZyItDEzeU6c/S0qL+7gsXybgFyPT5qtGRquU/oRUxW8ZKmkRFaeIfIhhN20dfhXH+3UslLkv2vlh1/RygaoMCGTPwxHyWNQt6s/uS2yOKKgRbIc0K NRQbiuy3mfqL0z8LUWDA7s46l/OjiBBHfihoSVjodGfaZoaAGDRswtwIjXvwV5sq+uHiyIOsne8oRlZBMmcbV8zmjeFuiT5fvIZoqUaD3ejGQDMgwHvgAe1i 0L3vSIxrECKc+8CJT9crodype8MSCHF7pSsARUSrk/kf6Yf46kmP27SiE3jvXWhix9UpZmY3efuKVUQF+373YA== 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. 17:27, skrev Christoph M. Becker: > On 11.07.2018 at 17:19, Björn Larsson wrote: > >> 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? > This already has been discussed weeks ago, see > . > Aha, tnx.