Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:102737 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 72871 invoked from network); 11 Jul 2018 00:41:33 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jul 2018 00:41:33 -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.41 as permitted sender) X-PHP-List-Original-Sender: morrison.levi@gmail.com X-Host-Fingerprint: 209.85.215.41 mail-lf0-f41.google.com Received: from [209.85.215.41] ([209.85.215.41:42495] helo=mail-lf0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/1F-15421-B32554B5 for ; Tue, 10 Jul 2018 20:41:31 -0400 Received: by mail-lf0-f41.google.com with SMTP id u202-v6so19824105lff.9 for ; Tue, 10 Jul 2018 17:41:31 -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=KLeSHNCzvq+pygP3xHRpayilQd4e6/zfLTc+ByT/Jks=; b=WpQ9l+EWUPiwt8cUahhgoPcgxU1lWakD/7DrTl6c0LQjVEfR6mi83sLmBiV3NOuJNu +w5nbx7UVob34T4B2Y+etnFHu2YS+I5U3kG+sK0xcULPgc4pp0O425u4gjHBrNrDVdqq 2dg91N8fpaXSS/1E310/fbfUpnlr/igG0Wq+opcJVUXf/FP3vDzbL3vZ1Ieyu/1jdahq 6pdnIkjWXu6B3D+83QEA6IERSnM/4GC4v2CmB7l+sYMT2C9U5Jh6bx3NtBxzaONfFGF8 uKQsMso7jbiHzramTOQwk8G1wNtt78Gs5HwvzaCwfJ5RIGALkLkzHHZ0lxXMzWtDXtj+ 9jtA== X-Gm-Message-State: APt69E3FsT7gNebXJT6X1T+Z0kJIid8VZwfRmO5HR82SFa6QdDOU/BxV CQQLLrlYVV7E9U3Aa+eNKWlHQSX0tzOlzhrcsD8= X-Google-Smtp-Source: AAOMgpfKtAHWQthtDda+ZLbl1HnjJYejn5uhRmxapuRVDHccBQWVb0YenGCseZ5M33nRjh29gmBovvncEHG8YQDpzHk= X-Received: by 2002:a19:d313:: with SMTP id k19-v6mr4145074lfg.29.1531269688569; Tue, 10 Jul 2018 17:41:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 10 Jul 2018 18:41:17 -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 12:59 PM Pedro Magalh=C3=A3es wro= te: > > 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/warni= ng, > > 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 distinguis= h > 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.