Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:127076 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id A651F1A00BC for ; Tue, 8 Apr 2025 18:46:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1744137845; bh=AU6wLGlRNaiWIWG9CWmusNjtJG9BcoWy7SPwDa3n3yI=; h=From:Subject:Date:In-Reply-To:Cc:To:References:From; b=cW5X3kYWWwvr7EEzw6r3SNWbqQujucS5lFViJR/MHYU7XyNxH0+hCJos3dKEZl9KZ iKKvdV+qN7UemXORRD5g8y+Q+NVJoXneIfObdOKl/nF6x34UZ72kjs120ucAQzOkpM YqegoNWFeStxt21LqBNI39wtDSbW30UbunC7d21PygEGxBthI2nAa5qfnETqWMrSBq NcogGFZ9rF79x2AK14jL7sVG3Gv8Vrkb//CaC6QrDLauhfrtybGA0If0rCi/fLsvUK eGYbuxm/aKFJZMNbbsxkGf2XmpEy8KMWnzTBOGwthKCeWyNswqGqXTAg6p3QLNXFQs RBYavAxmRX15w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 15F511801C7 for ; Tue, 8 Apr 2025 18:44:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,FREEMAIL_FROM, HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f49.google.com (mail-ej1-f49.google.com [209.85.218.49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Tue, 8 Apr 2025 18:44:04 +0000 (UTC) Received: by mail-ej1-f49.google.com with SMTP id a640c23a62f3a-ac6ed4ab410so954194166b.1 for ; Tue, 08 Apr 2025 11:46:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1744137988; x=1744742788; darn=lists.php.net; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=2w/Zhl7bUDdRdO2gTMFRBaB6RE2bu0xV5E/q7K8B9qg=; b=mg9w+Gd6qjGzmHFtvwlS/kl1IbGxB+1axTGKqHL9Jzk35acTIQIGvk4N0sYSleg9oi vvsqO63F3yyR8NTZq8yUXdaT+hsk7xgrkStE/v1IScTDLVf10/T2BDHiSph6pUgsLV+5 /Ror5gTO11iISZ077vAEotPodBEfAfZLIOFwEN7UDvO6JuCZ9t+kVYVxIpn0mSN6DN2c oeTm7gys8rQINRXqATyZ+y+3jOSvPM6k4SzFhSHgsWobTMfEYY2MeZz7FPk4P3iMfJZO echmPlbvd0IZSfR7sAuvEOfen/5EOkGrEtyc/TXpgGH3OWoUq1DP1/0N0iYEUzRpMrB+ 2B2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744137988; x=1744742788; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=2w/Zhl7bUDdRdO2gTMFRBaB6RE2bu0xV5E/q7K8B9qg=; b=HW60oa2509EK6MYl3MluXyBd+IVX8tBH68wUAs3P1QyNgGVUzG3zrDTRjEZMEkbDRS uO8WC8mBAIq3ISb6pKWdn43meHEPUGTaV3inY2miWYMdcQmQaDA8NfbhVohD4LOyGmfw 2+6Hzz3sEVMZ1izWcsQ1ib+o+XWiLQ2liNZqsa+bfn4LQa8Yx0RDx1qGI3TA3XTnti0Z k2nsHcJkE0JSY7gKaj3ycLHKyTKqu022g41CkyAMMiAouQp5IyZvrlmBQ8jN9VD4kzru eVglBxJrbA9D9JY/myG68ISrfArSpniFEHiNx+JfPY4rKgmTDVvccGILJ8uhybPCshCt beCw== X-Gm-Message-State: AOJu0YzADdje24PbY/AX9Pr5uTQgjcWd3rUtT/z4p2HlJfz/l41ItulO Qobt8Vsahrk+Z5cMXhoekxBD33ePVpFbxyT1mPmsxMjNPdJDE8eu X-Gm-Gg: ASbGncsbid38eeWgEyrMm1kdMNmPG9gHU/gOdjYIERUmq6ivxTJzaHVLjQ4gEUxByE9 aGm2KtUn+yVAcrpKYru6AdTZFcZebulz9bJv0T1qdwxd/A3dK1yMXZ/U2O+GksLRI+JgrW3tdme hlnsK5waVAkN5+DE51QUm+7fnzyu0bjH8BzQulEPw6rZ5YFfdfJ1WGWjGhUhufm/xpduRpei/m5 1sPLxWvgIPby9/el3gjpSvOW5fDF4HGvp+1iUyZTuXeMRPhJs2HhHf7WAvJybh0drBWYtPV7DqZ 6GVpXt2ESLDcQTBnEdOTPcvCl+yRpYSMtJWCSAI/B9iWD+GKduZkvw/IMHKpcmxpgQkF X-Google-Smtp-Source: AGHT+IG06UHpsRUSrfRbtGCcR8QCBtnb+zSvwanihCpigTHVaTuNNmU+E+89YGeN/u9S06Amv0lhiw== X-Received: by 2002:a17:907:3cc5:b0:ac3:3f11:b49d with SMTP id a640c23a62f3a-aca9b036474mr41972366b.0.1744137987562; Tue, 08 Apr 2025 11:46:27 -0700 (PDT) Received: from smtpclient.apple ([89.249.45.14]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-ac7bfe5c5ffsm954103466b.23.2025.04.08.11.46.26 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 08 Apr 2025 11:46:26 -0700 (PDT) Message-ID: <62C3AAC4-0D41-470B-AB26-8FC92B59E0EF@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_F58C1F00-CE99-4520-BA78-38277CEFB8BC" Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.500.181.1.5\)) Subject: Re: [PHP-DEV] [RFC] [Discussion] array_first() and array_last() Date: Tue, 8 Apr 2025 20:46:16 +0200 In-Reply-To: <51fcec92-b2ae-482e-920f-c6c991b526c5@gmail.com> Cc: PHP internals To: Niels Dossche References: <51fcec92-b2ae-482e-920f-c6c991b526c5@gmail.com> X-Mailer: Apple Mail (2.3826.500.181.1.5) From: claude.pache@gmail.com (Claude Pache) --Apple-Mail=_F58C1F00-CE99-4520-BA78-38277CEFB8BC Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > Le 5 avr. 2025 =C3=A0 17:51, Niels Dossche a = =C3=A9crit : >=20 > Hi internals >=20 > I'm opening the discussion for the RFC "array_first() and = array_last()". > https://wiki.php.net/rfc/array_first_last >=20 > Kind regards > Niels Hi, I think that this argument is not convincing, and even = counterproductive: * NULL is a rare legitimate value, so the potential for clashing is low First, it says that it is a =E2=80=9Crare=E2=80=9D legitimate value, = which one can disagree with. (I do disagree.) Second, the way it is formulated, it implies that, when `null` is used = in array, there will be =E2=80=9Cclashing=E2=80=9D, which is not = necessarily the case. (I consider that there is almost never a clash, = because it is rarely useful to make the difference between an explicit = `null` and a missing value, and, when it is useful, you have almost = surely already checked for an empty array upfront.) I suggest to replace that argument with the two following ones, that = doesn=E2=80=99t treat arrays with NULL as second class citizens: * Semantically, NULL represents a missing value. Returning NULL from an = empty array is not semantically incorrect, but it means that the = function doesn=E2=80=99t differentiate between a implicit missing value = (empty array) and an explicit missing value (array with NULL as its = first/last element). * In the relatively rare cases you do want to make the difference = between an empty array and an array that starts/ends with NULL, you can = (and should) just check for empty array upfront. ------- One more thing. On https://www.php.net/, I read: =E2=80=9CFast, flexible = and pragmatic, PHP powers everything from your blog to the most popular = websites in the world.=E2=80=9D (emphasis added). If we were to design = some new perfect language, we might consider making `array_first()` (or = equivalent) choke on empty arrays. But given the current state of the = affairs, the pragmatic thing to do is to pave the cowpath. =E2=80=94Claude= --Apple-Mail=_F58C1F00-CE99-4520-BA78-38277CEFB8BC Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8

Le 5 avr. 2025 =C3=A0 17:51, Niels Dossche = <dossche.niels@gmail.com> a =C3=A9crit :

Hi internals

I'm = opening the discussion for the RFC "array_first() and = array_last()".
https://wiki.php.net/rfc/array_first_last

Kind = regards
Niels


Hi,

I think that this argument is not = convincing, and even counterproductive:

* NULL = is a rare legitimate value, so the potential for clashing is = low

First, it says that it is a =E2=80=9Crare=E2=80= =9D legitimate value, which one can disagree with. (I do = disagree.)

Second, the way it is formulated, it = implies that, when `null` is used in array, there will be = =E2=80=9Cclashing=E2=80=9D, which is not necessarily the case. (I = consider that there is almost never a clash, because it is rarely useful = to make the difference between an explicit `null` and a missing value, = and, when it is useful, you have almost surely = already checked for an empty array = upfront.)

I suggest to replace that argument = with the two following ones, that doesn=E2=80=99t treat arrays with NULL = as second class citizens:

* Semantically, NULL = represents a missing value. Returning NULL from an empty array is not = semantically incorrect, but it means that the function doesn=E2=80=99t = differentiate between a implicit missing value (empty array) and an = explicit missing value (array with NULL as its first/last = element).

* In the relatively rare cases you do = want to make the difference between an empty array and an array that = starts/ends with NULL, you can (and should) just check for empty array = upfront.

-------

One = more thing. On https://www.php.net/, I read: =E2=80=9CF= ast, flexible and pragmatic, PHP powers everything from your blog = to the most popular websites in the world.=E2=80=9D (emphasis added). If = we were to design some new perfect language, we might consider making = `array_first()` (or equivalent) choke on empty arrays. But given the = current state of the affairs, the pragmatic thing to do is = to pave the = cowpath.

=E2=80=94Claude
= --Apple-Mail=_F58C1F00-CE99-4520-BA78-38277CEFB8BC--