Hey Tim and Barel,

On 18.5.2026 22:11:38, Tim Düsterhus wrote:
Hi

On 5/18/26 22:00, Barel wrote:
I started the vote on this RFC:
https://wiki.php.net/rfc/array_get_and_array_has

As for the RFC itself - I voted against the RFC for the reasons that I mentioned in this email (non-array should error, not default): https://news-web.php.net/php.internals/130667


I actually think non-array should cause default behaviour, the same as missing.

The part which I don't quite agree with is having null as default - I'd rather have an error when the path does not exist, by default, and to default to a default value you need to explicitly specify it.


I also would suggest to replace a pure exists by a number how many parts of the path are missing.

E.g. array_path_missing($array, $path).


$path = ["foo", 0, "bar"];

if (array_path_missing($array, $path) == 0) // found.

if ($missing = array_path_missing($array, $path)) { die("Error: Key " . implode(".", array_slice($path, 0, -$missing)) . " missing"); }


Which lends itself pretty nicely to trivial nested array verification.


Overall I really liked this RFC, just the default behaviour of missing/non-array path entry is a bit disappointing.

I hope it'll be resubmitted with slight improvements there!


Thanks,
Bob

Reply via email to