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!!
Carlos
From: Barel barel.barelon@gmail.com
Sent: Saturday, April 4, 2026 5:06 PM
To: PHP internals internals@lists.php.net
Subject: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions
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!!
Carlos
Hey,
Very useful functions!
Why did you decide to not handle keys with dots? It would prevent these functions from being used in tools that might sometimes receive something like example.comas the key. The similar userland functions that I’ve seen do at least support the exact dotted key as well, even if not offering a full dotted<->nested equivalence with priority rules, partial nested-dotted and other fun stuff.
I’ve also found it quite useful to have [‘user.name’ => ‘Alice’] be equivalent to [‘user’ => [‘name’ => ‘Alice’]] for testing/mocking more complex structures.
BR,
Juris
Hi Carlos,
This sounds interesting.
A mature solution used in JS is lodash, with the get and has functions:
- https://lodash.com/docs/#get
- https://lodash.com/docs/#has
Also, from what I could search, Laravel array helpers have this
functionality as well: - https://laravel.com/docs/master/helpers#method-array-get
- https://laravel.com/docs/master/helpers#method-array-has
I was curious; did you research both, and maybe also other libraries? If
yes, it would be nice to mention this in the RFC.
They have some options, like allowing the key parameter as a list of
strings as well.
And also escaping the dot in the key in one way or another.
--
Alex
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_hasThis is the link to the proposed implementation:
https://github.com/php/php-src/pull/21637Thanks!!
Carlos
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_hasThis is the link to the proposed implementation:
https://github.com/php/php-src/pull/21637Thanks!!
Carlos
I echo others comments with regards to looking at / comparing to
existing implementations (particularly Laravel, given its popularity),
and escaping.
I would also suggest that the function names should explicitly indicate
they use dot notation to reduce potential confusion over which array
functions accept dot notation and avoid potential conflicts should
similar non-dot-notation equivalents be desired (for these or any future
dot-notation supporting array_ functions)