Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:121366 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87246 invoked from network); 18 Oct 2023 02:11:22 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Oct 2023 02:11:22 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D93151804BC for ; Tue, 17 Oct 2023 19:11:20 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS9370 160.16.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail.sakiot.com (mail.sakiot.com [160.16.227.216]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 17 Oct 2023 19:11:19 -0700 (PDT) Received: from smtpclient.apple (233.68.239.49.rev.vmobile.jp [49.239.68.233]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by mail.sakiot.com (Postfix) with ESMTPSA id 37F86401D4; Wed, 18 Oct 2023 11:11:16 +0900 (JST) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Mime-Version: 1.0 (1.0) Date: Wed, 18 Oct 2023 11:11:03 +0900 Message-ID: References: Cc: Levi Morrison via internals In-Reply-To: To: Brandon Jackson X-Mailer: iPhone Mail (21A360) Subject: Re: [PHP-DEV] Two new functions array_first() and array_last() From: saki@sakiot.com (Saki Takamachi) Since reset() and end() return false when the array is empty, in a sense, th= ere is an idea that there is no need to take such strict care of the return v= alue. If you were to take proper care, you would probably specify a default value o= r throw an exception, as has already been suggested. However, specifying a d= efault value is not very smart in my opinion. The fact that what value is considered to be "unable to obtain" changes depe= nding on the situation causes some complexity. And when dealing with an arra= y whose values =E2=80=8B=E2=80=8Bare completely unknown, it becomes necessar= y to "hope" that the values =E2=80=8B=E2=80=8Bdo not conflict with the defau= lt values. Can the following signature meet your requirements? Or will it become too co= mplicated? ``` // arrar_first(array $arr, bool &$has_value) $value =3D array_first($arr, $has_value); if ($has_value) { // array has items // $value is mixed } else { // array is empty // $value =3D=3D=3D null } ``` Regards. Saki=