Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130635 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 C74151A00BC for ; Tue, 14 Apr 2026 17:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1776186399; bh=rpAxjbieP/QGJQyfehnMVb6Myy0wdZg0x0VrPB+oK7Q=; h=References:In-Reply-To:From:Date:Subject:To:From; b=VD22vF6j2+WzyIRWJPxXlTSW5O5+aFFlcvkcaigJu7ES1nfaa2I8LEnc77Qx5Mhbd a85kiBcoarKLLvDtdHERdHi4EG98mPcmga5V/m2Tm2TW3MB4svJXCroNQ+LgqPwd7j 5E+x7rksdVyZW8kQLjKwydXQYhKGAy+eu72k+pyfXLU4ckOszZt+NqtJom1tAP9XBN pNOxvrvQOugcyItu/Bj3IbOVp3khn1x9Jb2j3/IhAxRVzb5vGxVajuHkRvO+NfOBG+ CwcWHn5v78aa98mBUqVPtOWVxyytEagP/PEnBahurcxQ21ognVYjFtX2AaOkOYfshl e+8Pk7w1TB/4w== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 9F2C01801DE for ; Tue, 14 Apr 2026 17:06:38 +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-qk1-f175.google.com (mail-qk1-f175.google.com [209.85.222.175]) (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, 14 Apr 2026 17:06:38 +0000 (UTC) Received: by mail-qk1-f175.google.com with SMTP id af79cd13be357-8e0a768331cso258838685a.0 for ; Tue, 14 Apr 2026 10:06:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1776186392; cv=none; d=google.com; s=arc-20240605; b=EkiXPr0VTkUF1Romeb3TVNOY2QNIcuijLhteokZuj4wYEbGy1JPegQy+CM+tMmH/Lo uPTZJxovaAySwdVVNut4dtgEnTgSs/T1Ir7oktGk+4ur+OsNLABb0Xpml7NUohoeyZ3P UW2J9iv0NSy/DYphfWMorhJDJDc4mrq2m31DNzv6BPCFWSrf6mtCmYeyoHMKTPMtAgm1 0TRuw95ZLzP1f9Ro1D4g0AxJfY+Y3oYO/bqjK+bE92eVVJZ3hDAFiCW+Fw69oya9UT+9 ENw8teMqfMz0q+fZIhg2j1Zz6KiDyyISJeSOssqhJ/6SMOA7CsM/PTlojaKEFi8j6NZx EyJw== 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=3RoUH+5aKoX74hroN0AfmslW3Qel2NxDcEbgz4Cwdw0=; fh=RnZ+4KjfdZdxwVfzmjFoBvUAaJ227RJecqE9MM9tvfQ=; b=XGNayHBDNmesdRsD2t1rxMQrRZxqirwCWMfCvusR2KjeVRlOIjgEsAIykch/GDuNph 0gX6YBf8P4t5JFNoM9LZ0ITOCyeH2Ux2MkNZoYgJ/CRQj0V0OeSnsvSm4FFoxpPiZfEV G1PR6Lv6Zg1zmDz0rfw4FXlx4uUX+c5uhT30vzVGEew9yuJBM+EUbOjWBYm0ozB1u/2G eN66no1dIL2xw01RM2EfLoOuHw3EbE4MzrhHWWVUo4Em3qFRmhrUl5qHcQl1+kaPmDzV w968ScmvzdY+5mYlCQKlt9BcQBcreY6pIoDRU12JwSDVRvUOis8HYy+6w5nuGee79WUG QyzA==; 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=1776186392; x=1776791192; 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=3RoUH+5aKoX74hroN0AfmslW3Qel2NxDcEbgz4Cwdw0=; b=ZLs0iZnKwTmIUpRlbJd/f9rYQZPOYRfZAJUjrDTDlGh1l7qEL1ZGs0xqeQNTI2EdAb rH02pbGCQv9htUSEbBCeahYoK6+tBbktDyPWgt1NFDcEuLHSzHh2RzM6+mtMPeaajETN 8bPHfxMHocrrT/a7BUqprU73okvm1LKHsUvmkOWdjgJ0x9HNoGyTmAc4G027vcjwyrz4 9EXprI5bHS2zNdEjdbhnC/ci/2Y1Bjisf5vPjBlp+TASLzcTepGJNjuqnQNUpcyz754+ 4DaYW2HFRWihhR4QbhK7NYkSVp64wjPzImLbUGJ9+L/XQXMFGcwvzlCcLdpDDLSY5jLo 3gYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776186392; x=1776791192; 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=3RoUH+5aKoX74hroN0AfmslW3Qel2NxDcEbgz4Cwdw0=; b=J80KmbA2R8gtmBaYfiKUbgA81WX/ZKuOHqpJxZPo5TGs5408hBAJEu5+EXHfBL+Rzl vaxKQMlbAmxm+K2nY/DM69O84SKIdbfLGLhwc7xR1DGXJRQYt3As33F7IY0vnfzjjuzB peAYATEkV30axu7dzAiWD5Mqj+wuUX3px8iDxYTdsNg8LA6hTCcGZaPEKpKea4517Oe5 C4ooMfnOJiTMiVYvjbQXdZfaIjCVtNIkNsPdga6dWqbiUcjgFNJ2nb73w+J35ueu+glG CzwpryuHGmMP6vpw3c1NrzGYE6VcvPwtjp1fstcuU7nvDtSa6bjQDpFybWrG9zUIFHCE 6m5A== X-Gm-Message-State: AOJu0YwO+m2qJcCiASczzBfhOp25GR0GzjDr352zSCQZ7PHFuMUvIXYZ IMSpNcYlBugZPrI2Ol8MidAQ+2vPHImFeWoNbXWDs5BuHB+MvJevGDu3fJT7YuujNL2bgDmAgZo SI9l4WHfcjejXtVzjVJyuIuNWbdKDM0n4beIi X-Gm-Gg: AeBDietEcMLbfdC98kv/jHrgf8skcvJ9EHd9Jv6GU/IkBkomyptTIRMaX+29sWjIp20 tSGwp+uyQh/4cwWKdYUrF/zbB+NWQ1MZROm4aZVKGuFgz9x+/zmSp8zevXryPPE9WuIP3DetNGc F79G/tN8itGShNWK0tNdVW+rI0O5XAyo8dZiCZhqyB++zxXnF0N45AjlhxT9uITVAHmhEqo5huZ 59GcIrlDR9OCCm8IMcbLVYxzLIcLOu2Mexl92w+N8OS1fU6Wz5cLkeNS5m0uYCDsO2EJKrcsbgX SgJQ9mM0bJjtqohz2/Y9uU9gQPiYLmAmPmrw2YngXfKdn58f X-Received: by 2002:a05:6214:3216:b0:8ac:b4f8:b9fd with SMTP id 6a1803df08f44-8acb4f8c042mr93079326d6.27.1776186392484; Tue, 14 Apr 2026 10:06:32 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 14 Apr 2026 19:06:21 +0200 X-Gm-Features: AQROBzDywNw3YAgsG6hVSnb1udC-l4RjBV3QTv6EzXXcQf35DWmK1YUa_7e26dU Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions To: php internals Content-Type: multipart/alternative; boundary="000000000000fa9ef1064f6e9e8d" From: barel.barelon@gmail.com (Barel) --000000000000fa9ef1064f6e9e8d Content-Type: text/plain; charset="UTF-8" On Mon, 13 Apr 2026 at 17:23, Larry Garfield wrote: > On Sat, Apr 11, 2026, at 5:30 AM, Barel wrote: > > > After the discussion here and after speaking to other developers, I > > have decided to drop the dot notation entirely from this RFC and only > > leave the option to use an array path. Using dot (or similar) notations > > can be easily achieved using a simple explode or more complex code if > > we need to do more complex setups like escaping. The main goal of the > > RFC has always been being able to handle dynamic paths. The > > implementation has also been updated and is now much simpler > > > > Cheers > > > > Carlos > > "4) Using dot or similar notations " > > This should be bullet point 3, not no 4. > > I agree with Tim that an invalid path segment should error in some way, > rather than just using the default. If a non-int/string path segment is > encountered, it 100% of the time means the developer screwed up in some way > so they should know to fix it. > > One of the most common uses for structure-unclear arrays I run into is > (bad) APIs that have a value that is either a primitive or an array of > primitives. Can you include an example showing how these functions would > help in that situation? > > Eg, this JSON: > > { "state": "IL" } > vs > {"state": ["IL", "CA", "NY"] } > > Presumably you also have some real-world cases in mind that you've run > into. Can you include versions of those in the examples to get a better > sense of what usage would look like in practice? > > To Tim's naming point, perhaps `array_has_path()` / `array_get_path()`? > (Or maybe `path` first, not sure.) > > --Larry Garfield > Tim, Larry Many thanks for your thoughtful comments. - I updated the bullet point number - I agree that if an invalid path segment is found it is better to throw a TypeError, this has been updated - I see the point that Tim made about the function names, I have updated them to array_get_path() and array_has_path() - Regarding the issue of returning the default if an intermediate segment is not an array, the philosophy of the function is: if the path exists, return the value, otherwise return the default. This cover uses cases like this: in yaml configuration many times you set a config option to ~ (null) and this many times indicates "use the default config". So you may have something like: database: config: ~ Indicating that you want to use the default database config. If you convert this yaml file to an array an use the array_get_path function to get a value, for example array_get_path($config, ['database', 'config', 'port'], 7766), you want to get 7766, not an exception or error. Tim points out that intermediate segments might be objects which implement ArrayAccess, but allowing this would complicate the code of the function a lot without much practical gain. BTW, the URL to the RFC has changed and is now https://wiki.php.net/rfc/array_get_path_and_array_has_path Cheers Carlos --000000000000fa9ef1064f6e9e8d Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, 13 Apr 2026 at 1= 7:23, Larry Garfield <larry@garfieldtech.com> wrote:
On Sat, Apr 11, 20= 26, at 5:30 AM, Barel wrote:

> After the discussion here and after speaking to other developers, I > have decided to drop the dot notation entirely from this RFC and only =
> leave the option to use an array path. Using dot (or similar) notation= s
> can be easily achieved using a simple explode or more complex code if =
> we need to do more complex setups like escaping. The main goal of the =
> RFC has always been being able to handle dynamic paths. The
> implementation has also been updated and is now much simpler
>
> Cheers
>
> Carlos

"4) Using dot or similar notations "

This should be bullet point 3, not no 4.

I agree with Tim that an invalid path segment should error in some way, rat= her than just using the default.=C2=A0 If a non-int/string path segment is = encountered, it 100% of the time means the developer screwed up in some way= so they should know to fix it.

One of the most common uses for structure-unclear arrays I run into is (bad= ) APIs that have a value that is either a primitive or an array of primitiv= es.=C2=A0 Can you include an example showing how these functions would help= in that situation?

Eg, this JSON:

{ "state": "IL" }
vs
{"state": ["IL", "CA", "NY"] }

Presumably you also have some real-world cases in mind that you've run = into.=C2=A0 Can you include versions of those in the examples to get a bett= er sense of what usage would look like in practice?

To Tim's naming point, perhaps `array_has_path()` / `array_get_path()`?= =C2=A0 (Or maybe `path` first, not sure.)

--Larry Garfield

Tim, Larry
<= br>
Many thanks for your thoughtful comments.

- I updated the bullet point number
- I agree that if an in= valid path segment is found it is better to throw a TypeError, this has bee= n updated
- I see the point that Tim made about the function name= s, I have updated them to array_get_path() and array_has_path()
-= Regarding the issue of returning the default if an intermediate segment is= not an array, the philosophy of the function is: if the path exists, retur= n the value, otherwise return the default. This cover uses cases like this:= in yaml configuration many times you set a config option to ~ (null) and t= his many times indicates "use the default config". So you may hav= e something like:

database:
=C2=A0 =C2=A0 config: ~

Indica= ting that you want to use the default database config. If you convert this = yaml file to an array an use the array_get_path function to get a value, fo= r example array_get_path($config, ['database', 'config', &#= 39;port'], 7766), you want to get 7766, not an exception or error. Tim = points out that intermediate segments might be objects which implement Arra= yAccess, but allowing this would complicate the code of the function a lot = without much practical gain.

BTW, the URL to the RFC has changed and= is now=C2=A0https://wiki.php.net/rfc/array_get_path_and_array_has_path
=
Cheers

Carlos

=C2=A0
--000000000000fa9ef1064f6e9e8d--