Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102764 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 40188 invoked from network); 11 Jul 2018 16:20:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 16:20:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.52 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.52 mail-lf0-f52.google.com Received: from [209.85.215.52] ([209.85.215.52:34445] helo=mail-lf0-f52.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/99-15421-86E264B5 for ; Wed, 11 Jul 2018 12:20:56 -0400 Received: by mail-lf0-f52.google.com with SMTP id n96-v6so21750581lfi.1 for ; Wed, 11 Jul 2018 09:20:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=0HxKwWdvcJSmsuaHPIEWH7h6E+WlMF37lquDyYP+vnw=; b=Mt+ScwbCSJ+Ll616fBB84tzhuoMCEkpozAnIZj7qu4VJf3Et8eN7WzBeMs6ExzKrfW rYMhvjhWF22DWpW97YJitIVCCqY6Cj+Ye+OK710tJQPZ2LE28YXYNgPqh1GeZDSgwS7g gfC8PzONpev4uFXuDgparz2ZIy/DrYacyXhnsXAND6bzpAHWdYJ8qY4U/ePPAuuabsdn UnVRA+Zl8AMjRPwof6FxgsSW4P8VIi9sCYTft+JaajdSDq0dlO4NY9JJkxySk0sO5zrz NNendspY0zVfvxEEc7EeZZHvfiEPzyE9QNJAFmPyi1D2anDtLVQxvVMB+hxJU/CGplX+ +aww== X-Gm-Message-State: APt69E2cpT0hM2d/ygwXexGOMDvWeBsEE3UL7aWvA0HknckcE7Fz1tGl 01d4aWTSCPnirGwI/hIxNqXL53Om7BTcJfSFVkE= X-Google-Smtp-Source: AAOMgpctfsJWDvE0jGny0LDqUe/UXomj/bHSsr8G9ssd80lSfdq0i6MDtbmjsRocfJwReEXdg/NRLbTescGTIFe4pKU= X-Received: by 2002:a19:1749:: with SMTP id n70-v6mr6217599lfi.54.1531326052576; Wed, 11 Jul 2018 09:20:52 -0700 (PDT) MIME-Version: 1.0 References: <13b4eb91-6566-3724-d45d-aa63254e1f58@telia.com> In-Reply-To: Date: Wed, 11 Jul 2018 10:20:40 -0600 Message-ID: To: Christoph Becker Cc: =?UTF-8?Q?Bj=C3=B6rn_Larsson?= , enno.woortmann@web.de, mail@pmmaga.net, me@jhdxr.com, internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Re:[PHP-DEV] [VOTE] array_key_first(),array_key_last(), array_value_first(),array_value_last() From: levim@php.net (Levi Morrison) On Wed, Jul 11, 2018 at 10:16 AM Levi Morrison wrote: > > On Wed, Jul 11, 2018 at 9:27 AM Christoph M. Becker w= rote: > > > > On 11.07.2018 at 17:19, Bj=C3=B6rn Larsson wrote: > > > > > Den 2018-07-11 kl. 02:41, skrev Levi Morrison: > > > > > >> On Tue, Jul 10, 2018 at 12:59 PM Pedro Magalh=C3=A3es 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 mist= ake. > > >>>> > > >>> 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 =3D> null]). > > >>> > > >>> Regards, > > >>> Pedro > > >> To safely use it a call to empty or count or something needs to happ= en: > > >> > > >> if (!empty($array)) { > > >> $value =3D 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] =3D array_first($array)) { > > >> // do something with $value > > >> } > > >> > > >> People who argue against the tuple because they don't like the desig= n > > >> 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 > > . > > > > -- > > Christoph M. Becker > > This was not discussed, it was discarded. Enormous difference. As an example, it was claimed: > If I use a function I expect it to give me a return value which I can > use without any further post processing $wantedValue =3D > fancyFunction($someInput); But this isn't true even for the array_value_* functions. There must be pre or post processing because of error conditions. This was pointed out by myself and others, but it was still ignored. This is what I mean by discarded, not discussed.