Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130579 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 280001A00BC for ; Mon, 6 Apr 2026 15:01:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1775487689; bh=hWaQAxdsPWBQhOQnWICenaLxvGAaGXYd7kRWfFqbC3Q=; h=References:In-Reply-To:From:Date:Subject:To:From; b=k3BUfDGt7XWlICFbKAo72DnATJPE57+d5oFz1MFwuCEStkHiqj8s+egBT//6sa86j sl+9ASZ8XxsFedS2Fagf7yB3LTCjoulYuVo5Wy4zCRvXMYJmjnljCilW8Y729zfYHR LNNuDL4CudipL2YdMKMUIdeoe4geBHIWU9iV3C+xkimfuGB0qm29jKmfaQ9+QFR30L ZIh8WX+ZuTkaTxFakx7iXBqD0PVntPjrju2h0Vomf9akIbz7ItyQ58ugv9avdOMz6i HwMr8sg2varE9fBVVyad5IrmmTI6rxOGi1P6/pd122C2M4m9Ig3fPTOLaDqb1Lc7P+ Ax23FtQ+RMphA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id A2752180062 for ; Mon, 6 Apr 2026 15:01:28 +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_H3, RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 15:01:23 +0000 (UTC) Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-7dbccf6a23dso1935494a34.2 for ; Mon, 06 Apr 2026 08:01:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775487677; cv=none; d=google.com; s=arc-20240605; b=JmZKZAHACiW6wTi/DkBj/dcPDEYWIWUojoKzgMNv0mgJNAxT9ave4Ck6ACn3PZTQw2 EPVf4IQ2t3bpUn2ZcOZ3YGd0QY1gFt/myFeIPEPDUwPNyK9s9FQMUYcMnco7+/98EYiD WOOU4nLSbO8jewtIYAL7pr9W+Q6nnLbq4C5w5SeqsiMwfWdtk6NmhllJ9eOPYBWZilML MUZ3daaR9iigVJTdALPj2kiPZetWz4IvUJZmsXDdJYFQL0OD+fUXJYbE/lT7L7NPx8Q/ vycw8e+3Rd2ZBKBP0CTf5VEHfvx+GIdpeROO0xZG6syUKVro6ZsxZlvq2y9ZHACD1XJN D71A== 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=hWaQAxdsPWBQhOQnWICenaLxvGAaGXYd7kRWfFqbC3Q=; fh=PwvV1jWZOR90rDIG/6XexqaHJyAFBTdnFVhsS64qdEQ=; b=VXip2mHUnQtAYCDqYfWeFGzTGbxdhOmwjjAjYMHdC9Oj3ScAmNUWWz3+g0SJr7Pdrj kfFUhSw6Sd+pI3VY+SRyRJYthYKU1pexNbgFGnvR5+rKAHVfBqau+4ZU52jgnGQig1wb KbZfpi13JjXWNQrr0WVJH98VcqRu6h2tfhAVV20+9h0G06z7o2j/F812bnYXSGuBEy6C 0H17P9ZPOc+RGb9nfp3dYFMjlnj4SyQ85VIrrN8drdvp8itme2LC75RQ5nc58t8Wyx00 UuEbHEkWvgjbts95TDtRnnqFM4uUfgvEHBNIj4Z/hdWyg7k/QPBxsdgtajnG6rUDO11/ 1lmw==; 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=1775487677; x=1776092477; 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=hWaQAxdsPWBQhOQnWICenaLxvGAaGXYd7kRWfFqbC3Q=; b=Sv5Dl4j02YGfA2goxwD0Ugu6mNcJii+nh35JnapUSD2/Y3qpdARTK32kqtZgD5lF+M wPCvf7doi9AINdVid2QIIxCcXcU2Zu41/ke9yeLT9Lg0o+A13HC02QDEFcmHKT7hdWbj cPzfWQ5T/RZuW+cuoySJluIq9aqJ4lkK7vPHmDXnxWi1VEq7Ewn4nfdT0G0k+wGnP58I rGbFKVxpFJURgg94oU7JKB2r+2Mr+zhRra4uyMiCgMQY9YZBwppoCA4K+6U5+3Ok4pim jMJ89MgEFAV9P4GMLQv3fCPOWoHZNYaTDZ5/aPwZlnxz/TG9kxARag/9JSTFqYQQqsBz N0Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775487677; x=1776092477; 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=hWaQAxdsPWBQhOQnWICenaLxvGAaGXYd7kRWfFqbC3Q=; b=GRhmhcjmHdutxauKY9hv0+zP0AwunkF6vaG6odWYK/Oy/mUo6tZ22LjKRyM0bX8aeD dZrVoqLUHRWFnAemi3sQ86wmE1mSDZnflM2Ogds5Yol2gXfB85lpiS0s6J9jIJUbj4sf Gsic9wZK7Orkq2fJ+1XxiTe8kJaRn2cjul1f0H2HxxSA63Omoi78kQwvt/vf5pJF2+G3 5OCiNouwnUFMM6GlrVixMdsNcefZN3K8j1a3e3y5CEmeueeNJponC28g+BqjSu3qIY48 ohgoqQC9/jvK2B9fbxOgNscU1B1vUbBwj+YHKxbaKPUdQWBsTfl3aC+CpiLNDx2FKvNA zxng== X-Gm-Message-State: AOJu0YyeenvYX7mHqUI0WLuOrexYA5sNhtKxGSsofa61sUsXlPGhWAFK iLacF//vPTjF+FTkMYTGy04JwI9GXfsD3n8TLfotChtbrC8cKbkAWu8qENV7WoDopm0P37w5rIH WD9VCbt/vIX4iYJeV6optOhyYnZsvSj50Xw== X-Gm-Gg: AeBDievHyuqB7rSFlbcdsLGYOSeeZrWIGGVTo3ddyfMlqgix3U4De/mCr61muCGQ+tq ynGaxznZYj+tthwB+n5tccW4oBKxQ9O1t9o9cz3rhmT2nz/6CUg4FxHANgqtDkfdM0B8jSsW6fj 3ymJYFeuWmc9WXtv9nljva9VLNFZ1m1yAgJqC92GTkiZGXCFLPDOSOtbO5rQrNTlCuswCHozF5r x5VCQ39jEz2ENDC9WanBxV9u8IGY0pkaX4zWDG+7VwlBY6eaZZhEnT9dfDCqDuJaUpNauy+Hg8+ KPWDT+baHK6kAcwXFrsDD4mMqY4yxlO6PPBkOA== X-Received: by 2002:a05:6830:44a3:b0:7d7:fac4:e359 with SMTP id 46e09a7af769-7dbb7576c86mr6485499a34.27.1775487676858; Mon, 06 Apr 2026 08:01:16 -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> In-Reply-To: <1775385960072.803756451.2349920337@yahoo.de> Date: Mon, 6 Apr 2026 17:01:05 +0200 X-Gm-Features: AQROBzA-SXanj1XVgoAuQ6IKTVYM6swzT90eKe8YuN0vAh02fcvPUrs8Ne8Xq2w Message-ID: Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions To: PHP internals Content-Type: multipart/alternative; boundary="00000000000048457c064ecbf03b" From: barel.barelon@gmail.com (Barel) --00000000000048457c064ecbf03b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 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 chang= e Cheers Carlos On Sun, 5 Apr 2026 at 12:52, Hans Krentel wrote: > > > > > On Sunday 05 April 2026 11:43:03 (+02:00), Barel wrote: > > > 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 > elements > > > > 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 as= k right > 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 > > > mapped as an iterable with string keys, which can then be accessed vi= a > the > > > 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 the > > > JSON pointer would then not need to be recoded into dot notation, but > only > > > (if not 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 prefixing 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 itself to just JSON array= s > or > > > objects. This is just food for thought: array_... are clearly array > > > functions, so this =E2=80=9Crestriction=E2=80=9D is likely intentiona= l. In PHP, > however, I > > > can also imagine iterables that resemble 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 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 = 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 as= king for > this > > > in the early days of Stack Overflow, and if Symfony/Laravel have it a= s > > > well, that=E2=80=99s just another strong indication of such a prefere= nce. > > > > > > Thanks again for your RFC > > > > > > > > > --hakre > > > > > > P.S. Work on the RFC documentation for JSON Path finally began in 202= 0, > > > 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 s= tandard > > > library with such features at the same pace we did with JSON. Your RF= C > > > seems well-suited for this purpose. Thanks again. > > > > > > > Thanks for your comments. Someone else already suggested allowing array= s > > for the $key parameter and I am considering it, I think it will probabl= y > be > > a good addition > > Yes, I agree, and I suggest we also consider _iterable_ as part of this > discussion. > > Thank you Carlos as well for your work on these functions. > > --hakre > --00000000000048457c064ecbf03b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
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 fun= ctionality 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 con= tain 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 no= ne 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 Gi= tHub has also been updated with this change

Cheers
Carlos

On Sun, 5 Apr 2026 at 12:52, Hans K= rentel <hanskrentel@yahoo.de= > wrote:




On Sunday 05 April 2026 11:43:03 (+02:00), Barel wrote:

> On Sun, 5 Apr 2026 at 10:13, Hans Krentel <hanskrentel@yahoo.de> 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 tw= o small,
> > > focused array functions for retrieving and checking nested a= rray elements
> > > using dot notation.
> > >
> > > This is the link to the RFC:
> > > https://wiki.php.net/rfc/array_get_an= d_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 t= o ask right away:
> > Is there a specific reason to limit this to strings, integers, an= d null for
> > 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 accesse= d via the
> > holder variable, similar to the foreach example you already descr= ibe in
> > your RFC.
> >
> > If these two functions supported passing an array/iterable with t= he
> > traversal keys as a second parameter, this would be advantageous,= since the
> > JSON pointer would then not need to be recoded into dot notation,= but only
> > (if not 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 prefixing 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 itself to just JSON a= rrays or
> > objects. This is just food for thought: array_... are clearly arr= ay
> > functions, so this =E2=80=9Crestriction=E2=80=9D is likely intent= ional. In PHP, however, I
> > can also imagine iterables that resemble what you=E2=80=99ve alre= ady described in
> > your RFC, and from there it=E2=80=99s not far to the holder objec= t we see in JSON
> > and JSON Pointer. So please don=E2=80=99t confuse my =E2=80=9Creq= uest=E2=80=9D regarding
> > arrays/iterables with the first parameter; it=E2=80=99s simply ab= out 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, mo= re custom
> > dot notation, and that=E2=80=99s perfectly fine. I saw many peopl= e 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 pre= ference.
> >
> > 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 i= ts standard
> > library with such features at the same pace we did with JSON. You= r RFC
> > seems well-suited for this purpose. Thanks again.
> >
>
> Thanks for your comments. Someone else already suggested allowing arra= ys
> for the $key parameter and I am considering it, I think it will probab= ly be
> a good addition

Yes, I agree, and I suggest we also consider _iterable_ as part of this dis= cussion.

Thank you Carlos as well for your work on these functions.

--hakre
--00000000000048457c064ecbf03b--