Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130694 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 BF5191A00BC for ; Sat, 25 Apr 2026 19:37:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1777145841; bh=T/KxzZt4vC+1l8sDv24ycLB0mqVArZVgScov09HoMuA=; h=References:In-Reply-To:From:Date:Subject:To:From; b=S9HhrkVxGFSE5bOTyHexQlPsITyEVohUXvzal1j4ZUG7wGwlCOcbesIaXRA948odX Llev5qmEacX2oqQ49Bx4HC3HFeuA3Oct6j+UXEVy3Jouw8NAyT972wRpm8toALmbAl /B0ZOuJFromdKBaWiqetbFfSNeuZg2fDAuASXK/ItSSs5It/PZXtYVYEFPPSEd8V0k HbGq9jy60wsDDq5Bs3Sx9oZfO8VqYhya6cTwjFcKfsOlI6SJ2X0Wc/UBV7Np7qdQJb aIoZZAJAwnmG5y6to/c+ZT/nXhJbkBHokPeCszqYZM69kkg7hP7KO9lNOET+C12EP4 W7eo6BJyfMCzw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 61FF518005A for ; Sat, 25 Apr 2026 19:37:20 +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=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-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 ; Sat, 25 Apr 2026 19:37:20 +0000 (UTC) Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-8ee7ffd738dso549966285a.1 for ; Sat, 25 Apr 2026 12:37:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1777145834; cv=none; d=google.com; s=arc-20240605; b=BHtIBILx0FQGJB84aIeiBcdN4JBqjY+LHQRr7O8vHUHjg+F9eZXa/BZKe4O8R/hOIe icFfEx2Hvl5kCYRP963ZIasB1bv5wjM6IS69LhfJ5X2CH41D/DfRHp/TI6AaNBxxaVVd CtYORMq6WNnju1QieTR6gaRydOG3KNaRuG2v7hnWc1Sb81N4HsJu606AnjfLTXpZM59z IdWIuCBZKtqH95vO3EyV3f4MyH0cYxHY+/XMdcxqdtVA+ydE5zVcD4naerQdaaA30Pss qGrpi8+lYKrBIfgg4yR6OwfJWvNDfauqQSatt78Bx7Y5c2uK5Ix4gGghS0jg2X9fo9xs i3iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=1G7wKQzOu3thnLk+Dy+G8YSzoiViK2oVqjtPA9EJPd0=; fh=RnZ+4KjfdZdxwVfzmjFoBvUAaJ227RJecqE9MM9tvfQ=; b=D4tSeqzoXHW63AS4wZxAsUfusDW8xNwifdpMkBXMZl9Be2aILnth0iNSJzR1gbcRwe 5gjxJyeglYOGQo+dbnUVC6qRF+C1tlCDndbfSs/TkJ1QEXrC9jDDMy1WCgfMm0s4VK4E ZUBXgIDnmx+NvFArFgx4CbqoM33b2CNMxigP0XqF5GCnpDFivPYe6KV79ZIrnO+lTyiD x6Yg0Qs/eysvHHRTnzbIKfn1VVTkSZQIIMzyp34/q5mTBB8Cy4g37cqGMA7rzfihfrzm aTkXqDNniu8WdbBT/wIavaOB3sC83oTf8kIvyk9pxS5lS4pBJl7lHM2yzZM86e1ta6vX 4c1w==; 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=1777145834; x=1777750634; darn=lists.php.net; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=1G7wKQzOu3thnLk+Dy+G8YSzoiViK2oVqjtPA9EJPd0=; b=ZJOL8hM0LLQxOQOH90xfGHHhyrc3fk+4HUfyhZqiLUKQwX0n5Zhm67Qr99BVCCxTud jABSKwcbx8YOxb7RZR1jjsFDBDWBfMPA6/ZCqUF0Taj8MjIHGsoyVToOgRIMZP8CUCNt 0RMLCVK1rHHa/bwpkINhzQ/eeFDbC/xPIHgBJKs3PRWQJMdoIthq6WvmrETf0JxdMrut 4Ws8Jc8hTZXMmABtEEWo+ZxjB803Ob7XKo5CU/4oOpg70d5Kvq46WmRh0IiQGK1Rp1QB waPn3D/CxpKMeazw439Whyc+nkSASmsonGN+JwdyYRwgRIMoRcEZXbXVEMG3MGoc+reZ ITHA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777145834; x=1777750634; h=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=1G7wKQzOu3thnLk+Dy+G8YSzoiViK2oVqjtPA9EJPd0=; b=f9kNLhjW96qDb6RM/W1IjTd/WNmX7EqIN/CpIN6Sib8vFchmkUi6Y3FV17Odhjsu/F K+QaSxku7kj8bDHiSJZYE+Z/l7o1OKBn65r3Sr3G8x54s0U2VpXQGPd9bXG7MqjArAfZ x0Tx3RsW9VXnHrSziHIZsUw69Ezju7poqnpCSOTm9WOv3g+5Y03NaeOU+Dk17yOItXQ7 n9pt6+9IiTZjx0d9DMbH04nma5xL5Q5ENEcocTZNaqg6KNYqRXoPNuhuYpuj8hkL24lu IZHQosb0jFfHm83V8M/hRJBW6MZE419BjqkvLN0rRo8JIj/I4GT1Gf3PlDhWkPgk528I OhFA== X-Gm-Message-State: AOJu0Yx8fMfQkVS4RM7BRZDtUiVjOA793VByVNMdq2Xrt/h+OCt1hWJS ccraZf3SLR+PHWBkfwWskCfL7y8zDChT9/WIKn0AippUdMgRqphPBZFx7yguXam9vkbJJcv8z+l nrrxREznRxfhjc3wSiKqKfsXkd5JOjzXrfg== X-Gm-Gg: AeBDieu2yDKVXnlmkcEb0przd/oDKqoEfo1ZIBcpkHC8uiDJzIyfz5owbbuszvwK/j4 GMWpF2KAjy8DsDV1BA5tSJIOteRA1zJv8Y3zAvNLIyeUNhYySOElzWkpIPkl06b3pa87A/WjCWR a3Fq9casdiUzvCUC6YFoSjbBSJbH0hM4ZlYP8DEPsN4Wh7pYIYJisBJI9FP896GC51J8d6n/wQ9 Zr2A7jYGwwdZI+deOfsGJ7+Se4tlHoGqpVbr++UzjT3wqkycTWCnxPQAAw74MLdLvCJMaOM+8pZ DPP3R0edMV8ibYjfD92SRkDOK+/Md/63Tydn1R5J8NHwfNux X-Received: by 2002:a05:622a:a94b:b0:50f:f030:920d with SMTP id d75a77b69052e-50ff0309adbmr18916501cf.30.1777145834151; Sat, 25 Apr 2026 12:37:14 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <19d58a46b50222b75da4e40e417efd05@bastelstu.be> <4f684a4fbad3a7ddb797e24e3c1a882a@bastelstu.be> <8dca7d45-fce4-4d6a-ac56-956046ef20a6@app.fastmail.com> In-Reply-To: Date: Sat, 25 Apr 2026 21:37:02 +0200 X-Gm-Features: AQROBzBa5SIN_A9bpro0EEMmWM0zLLGfHaWyFK43GOSdG3SvW4NBj4MCaU3zaFw Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions To: php internals Content-Type: multipart/alternative; boundary="00000000000028a12306504e0215" From: barel.barelon@gmail.com (Barel) --00000000000028a12306504e0215 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Tim, Many thanks for your comments regarding the RFC, I have updated it. Regarding the issue of throwing errors if a path cannot be traversed due to an intermediate step not being an array, I tend to agree with Larry so I am leaving this as it is for the time being Cheers Carlos On Mon, 20 Apr 2026 at 19:07, Tim D=C3=BCsterhus wrote: > Hi > > Am 2026-04-20 17:18, schrieb Larry Garfield: > > 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? > > Yes. > > > If the array were clearly, consistently, and properly structured, we > > could reliably just do $a['foo']['bar'] and move on with life. > > [=E2=80=A6] > > 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?" [=E2=80=A6] > > The goal of the RFC is replacing `$a['foo']['bar']` where the *path is > dynamic*. Quoting right from the introduction of the RFC: > > > When the structure of the array is known in advance and the exact > > element to retrieve is hardcoded, existing PHP syntax works well [=E2= =80=A6] > > And quoting further from the introduction: > > > array_path_get() retrieves a value from a deeply nested array and > > returns a default value if the path does not exist. > > I'm arguing that a =E2=80=9C(value at) path does not exist=E2=80=9D is so= mething > fundamentally different from =E2=80=9Cvalue encountered on path cannot be > traversed further=E2=80=9D. > > > converting to an object > > I agree that the correct solution in the general case is =E2=80=9Cuse a p= roper > object mapper=E2=80=9D (such as Valinor) and don't see much personal valu= e in > having the proposed functions. But if they exist, I would want them to > behave as safely as possible and that includes erroring if they cannot > make sense of the data. Emitting a Warning when encountering an > improperly typed value across the path would also work for me, but I > suppose that others won't be in favor of *that* :-) > > Best regards > Tim D=C3=BCsterhus > --00000000000028a12306504e0215 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Tim,

Many thanks for your comments rega= rding the RFC, I have updated it. Regarding the issue of throwing errors if= a path cannot be traversed due to an intermediate step not being an array,= I tend to agree with Larry so I am leaving this as it is for the time bein= g

Cheers

Carlos

On Mon, 20 Apr 2026 at 19:07, Tim D=C3=BCsterhus <tim@bastelstu.be> wrote:
Hi

Am 2026-04-20 17:18, schrieb Larry Garfield:
> Just to make sure we're talking about the same thing here.=C2=A0 T= im, you're
> suggesting that this:
>
> $a =3D ['foo' =3D> 'bar'];
> $val =3D array_path_get($a, ['foo', 'bar', 'baz= 9;]);
>
> Should error rather than returning null?

Yes.

> If the array were clearly, consistently, and properly structured, we <= br> > could reliably just do $a['foo']['bar'] and move on wi= th life.
> [=E2=80=A6]
> So in that sort of case, I'm not sure it's useful to distingui= sh
> between "There is no baz key on the array at foo.bar" and &q= uot;foo.bar is a
> string, not an array, wat?" [=E2=80=A6]

The goal of the RFC is replacing `$a['foo']['bar']` where t= he *path is
dynamic*. Quoting right from the introduction of the RFC:

> When the structure of the array is known in advance and the exact
> element to retrieve is hardcoded, existing PHP syntax works well [=E2= =80=A6]

And quoting further from the introduction:

> array_path_get() retrieves a value from a deeply nested array and
> returns a default value if the path does not exist.

I'm arguing that a =E2=80=9C(value at) path does not exist=E2=80=9D is = something
fundamentally different from =E2=80=9Cvalue encountered on path cannot be <= br> traversed further=E2=80=9D.

> converting to an object

I agree that the correct solution in the general case is =E2=80=9Cuse a pro= per
object mapper=E2=80=9D (such as Valinor) and don't see much personal va= lue in
having the proposed functions. But if they exist, I would want them to
behave as safely as possible and that includes erroring if they cannot
make sense of the data. Emitting a Warning when encountering an
improperly typed value across the path would also work for me, but I
suppose that others won't be in favor of *that* :-)

Best regards
Tim D=C3=BCsterhus
--00000000000028a12306504e0215--