Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130573 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 366101A00BC for ; Sun, 5 Apr 2026 09:43:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1775382202; bh=twzY6BySsXSdEbLKb90ClRcs7fLipQd/MfkGGAvCRKs=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=D3Dhz+zszd9WmLsBzIfFuGM7/CteO/B28xrGYBeH2Y2BSDDtjCpf4EzqoQQ1eq0mk RK/1zGEdqq5RMqc+XtixHwb7DsviHuNEZV5U1p2xPBs4hG3xwz5NqRX0xyw344diiI PCkAR8x35LDIHO02u14SjuVWMqcgu/YwMFvJ3MULpA2szGyGot1ikRvmAPHHrQ63/b GzYIudP7du8/vTiWV9Jjvc6YUNwaR0EFSvy2WqpGNVLm1WXFhJJq73IQV0gUVjYSjv FN4wf0XnG5GCRmJVFXJlBZFQ2+il6ymIWaOnP9dyzm19nOLQbUle8PXy3zv12gn5S8 cfcTYobGMJP4A== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id D39391801EA for ; Sun, 5 Apr 2026 09:43:21 +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=1.6 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_50, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FORGED_GMAIL_RCVD,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-f42.google.com (mail-qv1-f42.google.com [209.85.219.42]) (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 ; Sun, 5 Apr 2026 09:43:21 +0000 (UTC) Received: by mail-qv1-f42.google.com with SMTP id 6a1803df08f44-8a016799d2cso43514416d6.1 for ; Sun, 05 Apr 2026 02:43:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775382196; cv=none; d=google.com; s=arc-20240605; b=Cy7TmeC6gUlIY8fN34AJTwGmp6brZ3SlFyGrn2iuikqSLaPyRWAlQKi5CXRsfrp+bY RZ5lWKnWgkhHtOFWq+cicXhbu+MUNP6WlZ85/BF+jzmrqeTJBQrxw9GBI0aKZiJySwFG QcQ3oVOqTVk+/sh8Y0M05GOrHCab9fkGvCY6zpRFKlz10NZ7KyFnTVHz3RsIpqqcPKNc rKN7l1jhH0PXG1wokrcrGWlFFZai0NGVOrCSBuEedKg2IqyCLuzkhnjFauO1JKScWw8y wQF8W1Q+i9i7UEws/A8XIgR4pSTkKaJ4wkpexjyJGsdPBALAm/9mved2/NVSuBm7ncxo /KIw== 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=twzY6BySsXSdEbLKb90ClRcs7fLipQd/MfkGGAvCRKs=; fh=yqceb/xkt8A/66BbTQHWtFTfUCWjfMdokKoRZwnztEw=; b=ETKEoKN9sY0uGLpUIz0uQo1RiRI6zFp/8XVQwkmtMxUvXYDZEqq+PttMwSPjRK15Wm dJWrSTFUYqMJQhQMQAEVGllaKZqmsgHosKHcDYLz0+lOqZn0DqXoYo9g188a9pflDTeG X3U7OZ+4kqnngXBtJcgi7Sc1hu2TJzk83djITwfYV21AhdM5NKxRqUyjEy4BB+sl5p8X E4edLdvMP9MvJ8PVnwUxeBbzVpMvfu4MkWMEvt83SKG4k23tcjEW0cg6gQBt/HuAFqmU 4eRjxC3O4QfRFmKgyq3HYSsq0qQLIQOpH671nlo6xT/M+KaoS+4EnhMEowbYZu6UPsSj ClNg==; 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=1775382196; x=1775986996; 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=twzY6BySsXSdEbLKb90ClRcs7fLipQd/MfkGGAvCRKs=; b=lGSD+pbnck40GiLTJeMQdudXkGOwGHqgEe5RKkVySTRK8eR4dRgSXzzv1r6xiYTwDM yXRWvGI38wIRZGpR4OWEXQUtoBXG68ZIKL618qv8lheN9kvO4yEfttvzWQ1Edf1/rX+t rQrTuRmTYbhMB1LnkrZ08mTZt5DPrJZseCm5oAOUaxqWUepbMSBLVi35REdU6LrKaHU+ psq0CFENvrhdZup/cqsgzrenXRfBE4LZZ2OvIftHL3ha37MepFW2e2tE/XlG9W4Th3eE KwZYbmGvJUYTEnpS8CkEJNiq3Ox8Rz8iTMPCOU216ax7KUWWyMCW1aPKgSmGF/yI9/Lw vlXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775382196; x=1775986996; 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=twzY6BySsXSdEbLKb90ClRcs7fLipQd/MfkGGAvCRKs=; b=DLDbv2tjY6X0xk8q6PKfwNr8CN4rgwM35GGG1cg+1SNiQr7+Ijs1gVd44B/aIaPpZB JXpAdUptdyw1lwX95VqSvC2/t4nzgj/G6GWqKeKq6Di8qNlJ1GCiENXooo2tBHHYFlVd uskyPMRU65ugrmUmbGfytGUFemHfbWW86/Iyh4LfRUB2lY2KGAh66zaP6CfiiXIicMK3 HtXh7BLviIai7v88xywSO9/87IZIS2NL9qH0lnBojXqh5p15su2XCUwiHNH3VzO+51K7 6HFOPbkmflOPpy9HqV+F0mwGkv0tmEL2iFLcepm0c0jWjZzOcnXKoAgVMFwWlczrJS3K tncw== X-Gm-Message-State: AOJu0YwDKKC0OrZCxgFAvT9IctfWfbJP6xZCZRDjAvSwOzi/4JCPvocC lIiPAEUT6B6egNAUj3QcZX07GQDKe+iXGDUSyFadzYda37ZpNjVZaFoCcvW8XXcn9Uuueop+OEJ qIrR7ZOk0rD++04yTeapEJbUCDpEX0cv56A== X-Gm-Gg: AeBDievNYxGeLW4rugj14db+UQ1kqCFVgG1GH4yufKfvVOlEMmSxcmGweY6In2PL3vd 9yxC7vOsgQIEYSMfDY4eVPGpe/kLtUgtMBCRZfUNo79odHqNK7XdlHCXBmxxKfjOmy5/iLV9uRw XlbQuTesPGaz4PJVz/MM/FXMFTs9smCIZo4aroaafMyjHp1nFSiLnhuYF8JR2fuQk6qH1nu2Agu VTSptoxF57tEf0u0C1Hzb+w0zKwA8OnA0gZJkNKeWdfBqOlcbjwmMSCXKIUmc3TphaRiIDgjG+U +scNVU6aFr/NY6O0TOXZ/yY7xkqKTrff6Vb53w== X-Received: by 2002:ad4:5e8f:0:b0:89c:4985:83e3 with SMTP id 6a1803df08f44-8a704fa67a2mr146537116d6.49.1775382195919; Sun, 05 Apr 2026 02:43:15 -0700 (PDT) Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 References: <1775371239896.1388335648.2022649470@yahoo.de> In-Reply-To: <1775371239896.1388335648.2022649470@yahoo.de> Date: Sun, 5 Apr 2026 11:43:03 +0200 X-Gm-Features: AQROBzD0jQpyKGZidPgpo8o-qZqxB-E4wt2_BayRI4BZ7Ihis_nwm8kuZw6AaCs Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions To: Hans Krentel Cc: PHP internals Content-Type: multipart/alternative; boundary="00000000000020deae064eb36115" From: barel.barelon@gmail.com (Barel) --00000000000020deae064eb36115 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Sun, 5 Apr 2026 at 10:13, Hans Krentel wrote: > > On Saturday 04 April 2026 16:06:21 (+02:00), Barel wrote: > > > Hi, > > > > I would like to open the discussion on my proposal to add two small, > > focused array functions for retrieving and checking nested array elemen= ts > > using dot notation. > > > > This is the link to the RFC: > > https://wiki.php.net/rfc/array_get_and_array_has > > > > This is the link to the proposed implementation: > > https://github.com/php/php-src/pull/21637 > > > > Thanks!! > > Thank you very much! That=E2=80=99s very interesting, so I have to ask ri= ght away: > Is there a specific reason to limit this to strings, integers, and null f= or > arrays, rather than also allowing arrays or iterables? > > This reminds me of JSON Pointers (RFC 6901), which can usually be easily > mapped as an iterable with string keys, which can then be accessed via th= e > holder variable, similar to the foreach example you already describe in > your RFC. > > If these two functions supported passing an array/iterable with the > traversal keys as a second parameter, this would be advantageous, since t= he > JSON pointer would then not need to be recoded into dot notation, but onl= y > (if not already done) sliced and passed as an array as the second paramet= er. > > That's why I'm asking. > > Interestingly, JSON Pointer solves the =E2=80=9Cnull problem=E2=80=9D by = prefixing the > zero or more reference tokens (keys) with a slash =E2=80=98/=E2=80=99, an= d it supports all > seven types of JSON values without limiting itself to just JSON arrays or > objects. This is just food for thought: array_... are clearly array > functions, so this =E2=80=9Crestriction=E2=80=9D is likely intentional. I= n PHP, however, I > can also imagine iterables that resemble what you=E2=80=99ve already desc= ribed in > your RFC, and from there it=E2=80=99s not far to the holder object we see= in JSON > and JSON Pointer. So please don=E2=80=99t confuse my =E2=80=9Crequest=E2= =80=9D regarding > arrays/iterables with the first parameter; it=E2=80=99s simply about pass= ing the > key as a keys, which is a small improvement over dot notation. > > With arrays in PHP, users will likely prefer the non-standard, more custo= m > dot notation, and that=E2=80=99s perfectly fine. I saw many people asking= for this > in the early days of Stack Overflow, and if Symfony/Laravel have it as > well, that=E2=80=99s just another strong indication of such a preference. > > Thanks again for your RFC > > > --hakre > > P.S. Work on the RFC documentation for JSON Path finally began in 2020, > and it was published in February 2024. The standard has its roots in PHP > and JavaScript, and perhaps it=E2=80=99s time for PHP to expand its stand= ard > library with such features at the same pace we did with JSON. Your RFC > seems well-suited for this purpose. Thanks again. > Thanks for your comments. Someone else already suggested allowing arrays for the $key parameter and I am considering it, I think it will probably be a good addition Cheers Carlos --00000000000020deae064eb36115 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Sun, 5 Apr 2026 at 10:13, Hans Krentel= <hanskrentel@yahoo.de> w= rote:

On Saturday 04 April 2026 16:06:21 (+02:00), Barel wrote:

> Hi,
>
> I would like to open the discussion on my proposal to add two small, > focused array functions for retrieving and checking nested array eleme= nts
> using dot notation.
>
> This is the link to the RFC:
> https://wiki.php.net/rfc/array_get_and_array_ha= s
>
> This is the link to the proposed implementation:
> https://github.com/php/php-src/pull/21637
>
> Thanks!!

Thank you very much! That=E2=80=99s very interesting, so I have to ask righ= t away: Is there a specific reason to limit this to strings, integers, and = null for arrays, rather than also allowing arrays or iterables?

This reminds me of JSON Pointers (RFC 6901), which can usually be easily ma= pped as an iterable with string keys, which can then be accessed via the ho= lder variable, similar to the foreach example you already describe in your = RFC.

If these two functions supported passing an array/iterable with the travers= al keys as a second parameter, this would be advantageous, since the JSON p= ointer would then not need to be recoded into dot notation, but only (if no= t already done) sliced and passed as an array as the second parameter.

That's why I'm asking.

Interestingly, JSON Pointer solves the =E2=80=9Cnull problem=E2=80=9D by pr= efixing the zero or more reference tokens (keys) with a slash =E2=80=98/=E2= =80=99, and it supports all seven types of JSON values without limiting its= elf to just JSON arrays or objects. This is just food for thought: array_..= . are clearly array functions, so this =E2=80=9Crestriction=E2=80=9D is lik= ely intentional. In PHP, however, I can also imagine iterables that resembl= e what you=E2=80=99ve already described in your RFC, and from there it=E2= =80=99s not far to the holder object we see in JSON and JSON Pointer. So pl= ease don=E2=80=99t confuse my =E2=80=9Crequest=E2=80=9D regarding arrays/it= erables with the first parameter; it=E2=80=99s simply about passing the key= as a keys, which is a small improvement over dot notation.

With arrays in PHP, users will likely prefer the non-standard, more custom = dot notation, and that=E2=80=99s perfectly fine. I saw many people asking f= or this in the early days of Stack Overflow, and if Symfony/Laravel have it= as well, that=E2=80=99s just another strong indication of such a preferenc= e.

Thanks again for your RFC


--hakre

P.S. Work on the RFC documentation for JSON Path finally began in 2020, and= it was published in February 2024. The standard has its roots in PHP and J= avaScript, and perhaps it=E2=80=99s time for PHP to expand its standard lib= rary with such features at the same pace we did with JSON. Your RFC seems w= ell-suited for this purpose. Thanks again.

<= div>Thanks for your comments. Someone else already suggested allowing array= s for the $key parameter and I am considering it, I think it will probably = be a good addition

Cheers

Carlos=C2=A0
--00000000000020deae064eb36115--