Re: [RFC] [VOTE] array_get and array_has functions

From: Date: Mon, 25 May 2026 23:55:18 +0000
Subject: Re: [RFC] [VOTE] array_get and array_has functions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-131015@lists.php.net to get a copy of this message
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

« previous php.internals (#131015) next »