Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130582 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 8DBF91A00BC for ; Mon, 6 Apr 2026 16:21:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1775492508; bh=7tniMkkEg4ejeyCjQchj0kBo7gKRgOW1RZ5OK9TVnTk=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=TzU8+EOdfKvQmgOBvh4ohUOu8GPHgsypJajRSqYs6jIY8vXVvuLt7Y3TdAEGKfB7g Iz9e9zhMrLR9mHdNZNfaIS8pfsVH7+x3euhZStS+GPBXJyXoVfsDiuFmKsUetw2LIj SySm5j395TrCMYWZRN0cvzqV2ADScdeh2KUJzKweOgRjTM/VXVsMkL6f6uqZxwtoDQ b29FTmTuCDpU+YogU9cnGqT1kXqFC7B63g5tY0v4q3boM/SwU7xxewG8r6L2opr7U5 /NeoQz5HpM8+Yxc4bUMrDfUN0MZ+XjxPXi4betLVTINUgEVOJFph6CYHoukgQQ5oO+ /gI5AXyyMJgxQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 420871801D5 for ; Mon, 6 Apr 2026 16:21:47 +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.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,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_H2, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-qv1-f51.google.com (mail-qv1-f51.google.com [209.85.219.51]) (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, 6 Apr 2026 16:21:37 +0000 (UTC) Received: by mail-qv1-f51.google.com with SMTP id 6a1803df08f44-8a110e06b4cso53733846d6.1 for ; Mon, 06 Apr 2026 09:21:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775492491; cv=none; d=google.com; s=arc-20240605; b=J8xsyS91iKa9CYRuP/8Emhjhj2OGqkLCcG2NHUvU4avY7PFlxl3fk2q7mcQJHZnvIY nw0Yt4z3DrEd1ZkVZrkJAbqFxo7I1mQm50rDcFWlHQ50Lilaln9HkkNjWHkDSK0tB8r9 BhJZxE0YyAm45MJXT1CZ4nBYFF0g3ICtSzxCW21m3Rka2qQWGm9DHVvC0VR1ZLrp6hpa ahqg0fpMzEEGvpfTPPz7U4Y+qxKZ0GzHMhSPeRR/FtL+fWmH4kTMSwf4Q+KBoUxe992r uN5rj/PjFFA1fZxaPxLI5L0DAHzj1LC/mNAjh8uml8SotLFgtdLBgE4lLI2hnbEfddi0 rx2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=loGXfrzFzRG3+ChRSK/ySQp2sTTllAtLcrOPXZbzUvo=; fh=Ofn+XpSLefQyxrNYeqFK5V6BgIEzMTvoqvpJ6/SQfuk=; b=fo/2WQPo7ts7dmmQuSID+CmKv5LYZo6wWf42ilaPPoY35l3zOwS0NUyDy1iNhQ/7z1 8DCrZWWDSv7SmpF9NBxhi9I+zuFqM7+8wn17u3S3ro4Lll8LKf8vCIow23Q+e+JSyR1o IJ8v2IVcbCNld2uC7ti5QnlinWVVRly3f3f05qtLiaiakuYN6vkJmpTQHsjktfAz26ZF v4duVsg9qs/kp7T+7F1fSSJZOZaP33OmDClSpEJytWjdIz+BdT1OusHL0PzrGdSsD0wA MTfItO2YM9VpiFgoP25a3A6i9mAcj/Et3hiJGhdQRezArQJTNODjdrV6qHTUs6OHw5c4 TICQ==; darn=lists.php.net ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775492491; x=1776097291; darn=lists.php.net; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=loGXfrzFzRG3+ChRSK/ySQp2sTTllAtLcrOPXZbzUvo=; b=guco4orv/X/dYedH2tk1dMRQLeZkNijA3qJLS0R/qguvi815ZpzpioOddcWgGNAyuw 2hjdXDGuJY57rFrLn2QSTYamnfpaeaPDaXOhMu9VNrUBPWT2r2NKP6uFtx4EEZmNPvzK Me1tQ3qhwzGoyCFTrIuVfz1WzdE3zd+4xqBJWvH/jDkb0bEULuE+DTAogxpW4+Pfy7ef ocSyVEzo36w6d6ga9G6sqi36wZwLeTizOIes4Acn4HnhJdB1v94/790dlKmDCv5v8urR AIkjMRfAt37z5yShYhoZvBmHkzE1t+WuV5JklLduwcUr1zKmdBbrXGfux98KGfu7+5hj usuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775492491; x=1776097291; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=loGXfrzFzRG3+ChRSK/ySQp2sTTllAtLcrOPXZbzUvo=; b=Z3oNvY6C4V4iG283Xx1TcxOQ34SnLke3KKTHaRp/qPVrx0AAjWaLavPx88ZZBtVhr8 fp/8Ol5bt03LsQFYH/oorlReABcJ8egmgL7/QwukCPQKyjm4p0ezMVuGx8UrRZaTULQp L6SknaubQ1ZCzEEtiyYymNdXMRcJ2QRqFpu1WoJFktm4E13YaXR9cUZzt+xNud608HTn BY0ipzN+vBbmbXqvG9ecoSgyM5+3lh+E6RyIocaP9Zs50yUd+KHnUmJuP12PM30KfpJY ZM9cLJaXXkUqtRLrTLVkmt1FL0ySydOTIWhzkzUYJVdZ4hky8XPrm/Eox3d5KpU8TuZS Z+bw== X-Gm-Message-State: AOJu0YyvdankCSwmGiw3odqpod/D4t9wKkpbF2Ih8/r/A7X7t4Jnus+I 5feu9lbx46xc4aiiL3oEkEq4TqnLyX57j6P87ZhA1CYD76flLq+Eewc3n2AvI2jbTgnccYc3XgF Nj0/oEyn0YfCStkJVk9D1aQkn9SvXglgpyg== X-Gm-Gg: AeBDieutXFD6WQofv1w32BWKqBHdgS6ayr+7Bs47oZ6MERu3X1tAoyjbWvrNCngmPYL CpN5WpXjXBQxmoq66FL8K/k/DPoPADcNyblg4fWrKpkdkVpUPbPtZIwVkD5mOAid7buURSPA2cX tdvbseCNxV7P9L94hvEB+UmsTnh5nYCJMTHtILVSgl2+CwVJp8EAU6VuD6hOM7l+KmI/cx8UiiD yp3zHqqwLg0VKo2Xt37HxUMJtUgPiPSy03Fw2Zfu1NWA3u4eiaaIzX2TNmhBV934fumkIVXTiJ7 zbzpIoODRx2cITMGzP3VeXiWC3B+r9DI2D4OKQ== X-Received: by 2002:a05:6214:27e1:b0:8a1:e181:7c60 with SMTP id 6a1803df08f44-8a702c977b9mr212490006d6.25.1775492491323; Mon, 06 Apr 2026 09:21:31 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <1775385960072.803756451.2349920337@yahoo.de> <1b1eb4f5-4701-4ccb-94b7-42306c3f33b5@app.fastmail.com> In-Reply-To: <1b1eb4f5-4701-4ccb-94b7-42306c3f33b5@app.fastmail.com> Date: Mon, 6 Apr 2026 18:21:20 +0200 X-Gm-Features: AQROBzDfr1yeYDUxzYuROsYRNKai4a1GAXQNX1Ic_v88Rsk7YK_y5qYvA38c7Sc Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions To: Larry Garfield Cc: php internals Content-Type: multipart/alternative; boundary="0000000000003f2d07064ecd0f62" From: barel.barelon@gmail.com (Barel) --0000000000003f2d07064ecd0f62 Content-Type: text/plain; charset="UTF-8" On Mon, 6 Apr 2026 at 18:12, Larry Garfield wrote: > On Mon, Apr 6, 2026, at 10:01 AM, Barel wrote: > > Following some comments from some users I have decided to also allow > > the $key parameter to be a list of strings/ints so that this > > functionality can also be used without using dot notation. I believe > > this also removes the need to add any kind of dot escaping. If your > > segments can contain dots, just use the form of the function that > > accepts an array. > > > > It was suggested that accepting an iterable would be a good addition > > but none of the array_ functions accept an iterable so I don't think it > > would be good to make an exception here > > > > The proposed implementation in GitHub has also been updated with this > change > > > > Cheers > > > > Carlos > > Please remember to bottom post. :-) > > It looks like the RFC hasn't been fully updated for array-based "keys" > yet. The function signatures in most of the examples still say > string|int|null. > > Despite my long-standing and public crusade against arrays being used > where an object belongs, I'm overall in favor of this direction. However, > I would go all-in on the array syntax, not the dotted syntax. There's a > few reasons for that. > > 1. The various notes around escaping. Having a string instruction format > that doesn't handle escaping and encoding and other edge cases is asking > for trouble, and it's trouble that will be harder to fix in the future. > String instructions are always more complicated and nuanced than you > expect, so a simple "split on the dot and now it's an array!" approach is > just too rudimentary to be trustworthy, for all the reasons mentioned in > previous posts. > > 2. If you're not building the path dynamically, then there is little > advantage of it over what we have now. > > array_get($array, 'foo.bar.1.baz', null); > > $array['foo']['bar'][1]['baz'] ?? null > > The second may be slightly slower to type because of the punctuation, but > it's perfectly viable today. > > Where it becomes interesting is when the path is variable... and if the > path is variable, I'll probably want to be building it dynamically rather > than just selecting one of a few hard-coded options. And if I'm building > it dynamically, then string concatenation is an awful way to do that, for > all the escaping reasons mentioned previously. We're back to concatenating > SQL strings together, with all the risk that entails. > > So I would be in favor of going all the way to > > function array_get(array $array, array $path, mixed $default = null) {} > > Or, for that matter, that is nearly the same as: > > function array_get(array $array, array $path) {} > > array_get($arr, $path) ?? null; > > Which would allow using a variadic for the $path if desired, instead of an > array. I'm not certain that's optimal, but I think it's worth discussing. > array_has() would then follow suit. > > Then, separately, I would be in favor of a full-on JSON Pointer > implementation that can work on both arrays and JSON blobs, potentially (as > the two are effectively isomorphic). Skip a custom dot notation. Go > straight to the fully robust standard. Do not pass go, do not collect 200 > security reports. > > --Larry Garfield > Larry, Thanks for pointing out that I had not updated the example code to include array in the type, this has now been updated You raise some interesting points in your message. I would like to hear what other people think about them Cheers Carlos --0000000000003f2d07064ecd0f62 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


On Mon, 6 Apr 2= 026 at 18:12, Larry Garfield <= larry@garfieldtech.com> wrote:
On Mon, Apr 6, 2026, at 10:01 AM, Barel wrote:
> Following some comments from some users I have decided to also allow <= br> > the $key parameter to be a list of strings/ints so that this
> functionality can also be used without using dot notation. I believe <= br> > this also removes the need to add any kind of dot escaping. If your > segments can contain dots, just use the form of the function that
> accepts an array.
>
> It was suggested that accepting an iterable would be a good addition <= br> > but none of the array_ functions accept an iterable so I don't thi= nk it
> would be good to make an exception here
>
> The proposed implementation in GitHub has also been updated with this = change
>
> Cheers
>
> Carlos

Please remember to bottom post. :-)

It looks like the RFC hasn't been fully updated for array-based "k= eys" yet.=C2=A0 The function signatures in most of the examples still = say string|int|null.

Despite my long-standing and public crusade against arrays being used where= an object belongs, I'm overall in favor of this direction.=C2=A0 Howev= er, I would go all-in on the array syntax, not the dotted syntax.=C2=A0 The= re's a few reasons for that.

1. The various notes around escaping.=C2=A0 Having a string instruction for= mat that doesn't handle escaping and encoding and other edge cases is a= sking for trouble, and it's trouble that will be harder to fix in the f= uture.=C2=A0 String instructions are always more complicated and nuanced th= an you expect, so a simple "split on the dot and now it's an array= !" approach is just too rudimentary to be trustworthy, for all the rea= sons mentioned in previous posts.

2. If you're not building the path dynamically, then there is little ad= vantage of it over what we have now.

array_get($array, 'foo.bar.1.baz', null);

$array['foo']['bar'][1]['baz'] ?? null

The second may be slightly slower to type because of the punctuation, but i= t's perfectly viable today.

Where it becomes interesting is when the path is variable... and if the pat= h is variable, I'll probably want to be building it dynamically rather = than just selecting one of a few hard-coded options.=C2=A0 And if I'm b= uilding it dynamically, then string concatenation is an awful way to do tha= t, for all the escaping reasons mentioned previously.=C2=A0 We're back = to concatenating SQL strings together, with all the risk that entails.

So I would be in favor of going all the way to

function array_get(array $array, array $path, mixed $default =3D null) {}
Or, for that matter, that is nearly the same as:

function array_get(array $array, array $path) {}

array_get($arr, $path) ?? null;

Which would allow using a variadic for the $path if desired, instead of an = array.=C2=A0 I'm not certain that's optimal, but I think it's w= orth discussing.=C2=A0 array_has() would then follow suit.

Then, separately, I would be in favor of a full-on JSON Pointer implementat= ion that can work on both arrays and JSON blobs, potentially (as the two ar= e effectively isomorphic).=C2=A0 Skip a custom dot notation.=C2=A0 Go strai= ght to the fully robust standard.=C2=A0 Do not pass go, do not collect 200 = security reports.

--Larry Garfield

Larry,

<= /div>
Thanks for pointing out that I had not updated the example code t= o include array in the type, this has now been updated

You raise som= e interesting points in your message. I would like to hear what other peopl= e think about them

Cheers

Carlos=C2=A0
--0000000000003f2d07064ecd0f62--