Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102829 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92742 invoked from network); 15 Jul 2018 01:25:05 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 15 Jul 2018 01:25:05 -0000 Authentication-Results: pb1.pair.com smtp.mail=yohgaki@ohgaki.net; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=yohgaki@ohgaki.net; sender-id=pass Received-SPF: pass (pb1.pair.com: domain ohgaki.net designates 180.42.98.130 as permitted sender) X-PHP-List-Original-Sender: yohgaki@ohgaki.net X-Host-Fingerprint: 180.42.98.130 ns1.es-i.jp Received: from [180.42.98.130] ([180.42.98.130:38084] helo=es-i.jp) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E0/F0-39793-F62AA4B5 for ; Sat, 14 Jul 2018 21:25:04 -0400 Received: (qmail 23875 invoked by uid 89); 15 Jul 2018 01:24:59 -0000 Received: from unknown (HELO mail-yw0-f181.google.com) (yohgaki@ohgaki.net@209.85.161.181) by 0 with ESMTPA; 15 Jul 2018 01:24:59 -0000 Received: by mail-yw0-f181.google.com with SMTP id r3-v6so13084889ywc.5 for ; Sat, 14 Jul 2018 18:24:58 -0700 (PDT) X-Gm-Message-State: AOUpUlE4baJq2CkGeH/G7+SZCginECR8UjpphuzZYvwZn8ZyWIW3Am2i 3NWZJtassGOf6O7cLx+YByIZgmP7DHjtTqRZDA== X-Google-Smtp-Source: AAOMgpeBMy1oHnPYyKJb89QWg/+0uJRTVgKHP1guaqUk4v9v+c+RJFC9Jjt71rqOHzObEBxLhzbqXZM2sF1Z2xgaHck= X-Received: by 2002:a81:5287:: with SMTP id g129-v6mr5706246ywb.460.1531617892921; Sat, 14 Jul 2018 18:24:52 -0700 (PDT) MIME-Version: 1.0 References: <59.92.57182.80D864B5@pb1.pair.com> In-Reply-To: <59.92.57182.80D864B5@pb1.pair.com> Date: Sun, 15 Jul 2018 10:24:16 +0900 X-Gmail-Original-Message-ID: Message-ID: To: Andrew Faulds Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000007079c80570ff9493" Subject: Re: [PHP-DEV] [VOTE] array_key_first(), array_key_last(), array_value_first(),array_value_last() From: yohgaki@ohgaki.net (Yasuo Ohgaki) --0000000000007079c80570ff9493 Content-Type: text/plain; charset="UTF-8" On Thu, Jul 12, 2018 at 8:05 AM Andrea Faulds wrote: > Hi, > > CHU Zhaowei wrote: > > I voted no. > > 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. > > > > Regards, > > CHU Zhaowei > > > Since PHP supports null coalesce, it makes sense applying null coalesce by default. Many users do it for inputs. e.g $var = $_GET['var'] ?? null; > > Hmm. Returning null with no warning makes perfect sense for keys, since > null is not a valid key so there's no ambiguity, but for values it seems > problematic. On that ground I've decided to change my vote to No for the > value functions, but keep the vote for Yes for the key functions. > Someone who wants such behaviour could always do > ($array[array_key_last($array)] ?? null), I guess. > When array_value_last($array) is needed, users would want null coalesce almost always. When user don't want it, they can if (array_key_last($array) === NULL) { // Or if (!count($array)) { die("hey, no value defined"); } $var = array_value_last($array); This usage would be rare and use of ($array[array_key_last($array)] ?? null) for null coalesce is pain. It lacks API consistency as well. Therefore, I voted "yes" for both. Regards, -- Yasuo Ohgaki yohgaki@ohgaki.net --0000000000007079c80570ff9493--