Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130674 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 lists.php.net (Postfix) with ESMTPS id 9DDE11A00BC for ; Mon, 20 Apr 2026 15:18:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1776698324; bh=/iW4FFQ0pEuGr1dNiOrLXJ5W68EoLw/w/uWB3Lnbj5A=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Da3MMpEoAmFHoCuNY6WvI2PsRWx0cRCH0unoHZg7I8S2n83Ts+Z6ofw3689W/6fKd nRp1+SOPp53Vdu9i0NlgMcnzEgYKFkETDLbPXksigfXRQhoHj1/GAUqAP1WpX2ic7q SMEWtm0ZL/2WiR6Ks9JvJG8jzoez3LQY7vMolXzJTJxbd/CbXLuqgC8wToDA3XLWJc 5eG6g+K1xJsZLQrBE7itPCjcvHJ7xAWVJ+UU8IFjbuFhQSVTay5JRUeWpOv5diG+3r Qe8wVaUmeLNH+PRIOZb5+R9cJ08lD17IVPfw0AyMmVKoBdhSaRoOeQxjfMo44ACXPC 24kOn6yELRaKw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 79ACF180040 for ; Mon, 20 Apr 2026 15:18:43 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fout-b3-smtp.messagingengine.com (fout-b3-smtp.messagingengine.com [202.12.124.146]) (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 ; Mon, 20 Apr 2026 15:18:43 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfout.stl.internal (Postfix) with ESMTP id 480031D00213 for ; Mon, 20 Apr 2026 11:18:37 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Mon, 20 Apr 2026 11:18:37 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1776698317; x=1776784717; bh=puRXgLma2kLoGmyfodhup cB2nQ1ZibhW6dsHK2zwy8M=; b=hSvNeo+OCOSmLP1oALOvVQ6HUJjQH8EfDxFYn MIzjvWHrEV0Q9mY6ye0H9MvFL/WaCaB9MME3FzstiJSZ70xRhOwT08xppc7RNuJh 5KGamPgzq7PKshCfcyI35s6mv8K+RqDx6bQCTwKmBvIo/VRuGOCh7bCPJL2TD52U zQcssgRR6Q4P/yAk0MI02vGAT/zMA2W6JcympkmfR60SJRdFmVLzVkAhPW/sU8cn QoK4gtyBwFxB1wsrI2RgKJrh7UGgghXnRF1nqgkrV6eXbQlJe60GitbpGcHiAdqy i/nDSgKQUExOuLnGdeNveGoRZE5TinY8bFfRubAVijEXgCJFg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1776698317; x=1776784717; bh=p uRXgLma2kLoGmyfodhupcB2nQ1ZibhW6dsHK2zwy8M=; b=Ef6xgTqLFfoXuf/Dn 5immu+zy+YGDYPwEoyU+kqHTIrQ/s24e92ny9LiNOCjZFijk1O/lLLQIc7xEAx32 K0IsrRbBuuRPvW7M9FsAeDcMgK5ZCw2pxJm2naYyDvKeiVyKmwIDEWEclTCJoubC gwzxIaFbRVPEStqk8/EkjkAsS/p+idKK2bqTyyHWh8xCViqZHX+ulFakaIjDhSZ1 NIdGo5pvK6NF5Ps51Dv6+/6/33pKLFsTlbYX/SU8q5Li+/Vs71+Da0BvZwOnvpJK ZziJpQsSScTKdSiFO4ipgocAmfQUoLOOYKa/lDyPzy1bOMIXC+rt1t3njU5QYG5M iSurA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdehkeekiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtqhertdertdejnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhepffeiiedvhfdvgedutddtgeetieeugeevhfetheeffeeftedu iedthedtgeejueeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphht thhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhsse hlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id DAA7A700065; Mon, 20 Apr 2026 11:18:36 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AwW8RH0VV87o Date: Mon, 20 Apr 2026 10:18:16 -0500 To: "php internals" Message-ID: <8dca7d45-fce4-4d6a-ac56-956046ef20a6@app.fastmail.com> In-Reply-To: <4f684a4fbad3a7ddb797e24e3c1a882a@bastelstu.be> References: <19d58a46b50222b75da4e40e417efd05@bastelstu.be> <4f684a4fbad3a7ddb797e24e3c1a882a@bastelstu.be> Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: larry@garfieldtech.com ("Larry Garfield") On Sun, Apr 19, 2026, at 10:06 AM, Tim D=C3=BCsterhus wrote: > Hi > > Am 2026-04-18 08:06, schrieb Barel: >> I am still unconvinced about this. Your proposal seems to give the=20 >> `null` >> a special value and I think that in general the full semantics are le= ss > > null being a value indicating absence is by no means =E2=80=9Cspecial=E2= =80=9D in my=20 > suggestion. As previously mentioned, it's the semantics of `isset()`.=20 > It's also what `array_find()` and `array_find_key()` return. It has=20 > special syntax in types with the questionmark in `?Type`. It's what yo= u=20 > get when you read a non-existent value. > >> clear. And I don't really like the function throwing errors for paths= ,=20 >> I >> think that this function is great for defensive access to values, whe= re=20 >> you >> can be sure that you don't need to be checking the path all the time.=20 >> The > > Defensive access to me also implies throwing errors *where appropriate= *,=20 > namely trying to perform an operation that is not meaningful. Trying t= o=20 > access an array offset on a string is not meaningful and trying to do=20 > *something* is not likely what the user intended to do. Similarly user= s=20 > passing in `ArrayAccess` objects might reasonably expect them to =E2=80= =9Cjust=20 > work=E2=80=9D. Returning a default value instead of a clear error will= likely=20 > lead to them thinking they found a bug in PHP. Just to make sure we're talking about the same thing here. Tim, you're = suggesting that this: $a =3D ['foo' =3D> 'bar']; $val =3D array_path_get($a, ['foo', 'bar', 'baz']); Should error rather than returning null? If so, then I do not agree. The purpose of these functions, as I see it= , is for dealing with inconsistently structured, wonky, arguably stupidl= y-designed data. (Which is a lot of REST APIs in the wild, sadly.) If = the array were clearly, consistently, and properly structured, we could = reliably just do $a['foo']['bar'] and move on with life. Or trivially c= onvert it to a properly typed object. These functions are for cases whe= re those are not viable or convenient options, meaning cases where a giv= en value could be a string or an array, because the data model author ha= tes you. (As noted in a previous reply, I have run into such structures= where the value of a JSON key is string|string{}. It bloody well sucks= .) So in that sort of case, I'm not sure it's useful to distinguish between= "There is no baz key on the array at foo.bar" and "foo.bar is a string,= not an array, wat?" If that was a distinction that mattered, I'd be us= ing ?? or converting to an object or whatever else already. --Larry Garfield