Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102738 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 73432 invoked from network); 11 Jul 2018 00:41:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 00:41:56 -0000 Authentication-Results: pb1.pair.com header.from=levim@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=morrison.levi@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.45 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.45 mail-lf0-f45.google.com Received: from [209.85.215.45] ([209.85.215.45:36448] helo=mail-lf0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CB/3F-15421-252554B5 for ; Tue, 10 Jul 2018 20:41:55 -0400 Received: by mail-lf0-f45.google.com with SMTP id b22-v6so7409120lfa.3 for ; Tue, 10 Jul 2018 17:41:54 -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=7L/jeBAnusJk6cDJ3rV8Wm1yFA/SEAjewZwUJudPsrE=; b=bI0C8QkFvFzvb5RbT5b3z59lJNnvfQXx6WojxYhhGxzHQ/W1L8u2W3U3ZfuiyLFecB JUU9D4pVPF+9ULkf1OkjmtBzxSLK0u8/vl+PK4R63Rgjf3shh93nwy4PyxEtIhk+0+30 oNEX/IKVnq8xbapuF6GXFQIKp7st2LO02a5R1ogUXxdewAXq6q+szmq62KG3aHKBWI9T UUVAoT7qAcEdzcs5ZJXs/x9bkaqoF19sEQAw7s4B65pMdrDKeX2QB+SLIDvKmNzS9nX/ EePhCw03EvbqwoSVMdKa0GZtqcvZvijAygFLTJb232zMNmiUTcbaOgGRPzMW47c0iRvf XOMA== X-Gm-Message-State: APt69E2IXsLvt+jbXYgC+wUQVWRoo3fCOANWXVhDuZlHglP7bK5sb94W DDOdB769CqQqkLVJw4VCdxxepgMdmV0G3ODlE6I= X-Google-Smtp-Source: AAOMgpeF1Da/ezBRMqSz6lpJ5bza1L0g4T6Ae31lKp80ntFtv1U5iqxdDZuwMCohgW1bBVqw1/lxk86IYpMiUCP+wNg= X-Received: by 2002:a19:1749:: with SMTP id n70-v6mr4111718lfi.54.1531269711917; Tue, 10 Jul 2018 17:41:51 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 10 Jul 2018 18:41:40 -0600 Message-ID: To: mail@pmmaga.net Cc: me@jhdxr.com, enno.woortmann@web.de, 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 Tue, Jul 10, 2018 at 6:41 PM Levi Morrison wrote: > > On Tue, Jul 10, 2018 at 12:59 PM Pedro Magalh=C3=A3es w= rote: > > > > 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/war= ning, > > > is wrong IMO. I know we already do this in other array_* functions, b= ut 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 arr= ay_ > > function that still accepts non arrays just to return null with a warni= ng > > doesn't make sense at this point. > > > > With that said, I'd gladly vote yes if there would be a way to distingu= ish > > 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 happen: > > 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 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.