Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130667 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 A6BB01A00BC for ; Sun, 19 Apr 2026 15:06:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1776611188; bh=2ozMN0uR2rcjH3oPSCPFhRdGiLJMNbUChrXk/JZmOc8=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=MMluPAALQKRSwbxT1tAtVSBc/2gas+lKQt1jyMCMI6FaXlivbIavouw3E3ImInPwy DNOa18q+BBPQbd1WORliyRDbcfagxvdTlIghLatmPPMnZko0IRKhtGqcrpm/LgYTl/ b7T3iB3l+UfBCcS/Ai64zD0OxnFAIhYExon+m0gjhnOgkcQZ/RQ76fsOXghMFfZWl7 lkB1JMF9mXEP6sgrNh11cFLbStJTOCR0UiHyGyXavK0u8gisaCbJWp5AT5dy5r+Qn5 WGOIE5Fm3yTTekMn5II9S2+7DgaJmHxZJzaotFXpRZJfDcv587ILEBjT0SVDWT1Uev xkRScbgnF1Pxg== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3ACDC18006E for ; Sun, 19 Apr 2026 15:06:27 +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=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from chrono.xqk7.com (chrono.xqk7.com [176.9.45.72]) (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, 19 Apr 2026 15:06:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1776611179; bh=pZE771/HjxJ5dZBKo1jERgUnvSAh4bwxasXqspHlmqM=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=MlkKF0x+C2VIo4DhP09QPAqXOTI/2w5xfe5F235VSliTerMA7c48xX7ZH4gtOgkNH 13CcOWUm5u1wCVxSxSEcEbTgp5QvIzkkPVVUoM3ZbabDMkTwAo/VSYuOGwz17f0Xqq KalsjdWpS2dlsqWeXoIeUkZ5Z6vt1L8jczSgLEex68ekU+ohe48RjaJ+/Y3megVGfb z74BPvw6JN0JNZovIuf7tx5Shmdh/2nJhz1GyVY7lJy/tya9stV5gb8ScLOHRHNZ4e ZdDHsLPCkXw0nGJfb10oG1UNgFYuVkJOSq0LvRBoj7co1SyBpEMWvQFjIPssyfmIwz hm7nxdrVr7j3w== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Sun, 19 Apr 2026 17:06:19 +0200 To: Barel Cc: php internals Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions In-Reply-To: References: <19d58a46b50222b75da4e40e417efd05@bastelstu.be> Message-ID: <4f684a4fbad3a7ddb797e24e3c1a882a@bastelstu.be> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit From: tim@bastelstu.be (=?UTF-8?Q?Tim_D=C3=BCsterhus?=) Hi Am 2026-04-18 08:06, schrieb Barel: > `array_path_exists`. I have preferred to keep `get` in the function > name > because I think that `array_path` is less clear about what the function > does. RFC and implementation have been updated. No strong preference regarding the `_get()` suffix from my side. > I am still unconvinced about this. Your proposal seems to give the > `null` > a special value and I think that in general the full semantics are less null being a value indicating absence is by no means “special” in my suggestion. As previously mentioned, it's the semantics of `isset()`. It's also what `array_find()` and `array_find_key()` return. It has special syntax in types with the questionmark in `?Type`. It's what you get when you read a non-existent value. > clear. And I don't really like the function throwing errors for paths, > I > think that this function is great for defensive access to values, where > you > can be sure that you don't need to be checking the path all the time. > The Defensive access to me also implies throwing errors *where appropriate*, namely trying to perform an operation that is not meaningful. Trying to access an array offset on a string is not meaningful and trying to do *something* is not likely what the user intended to do. Similarly users passing in `ArrayAccess` objects might reasonably expect them to “just work”. Returning a default value instead of a clear error will likely lead to them thinking they found a bug in PHP. > existing implementations in Laravel and Lodash do not throw any error > if an > intermediate value is not an array (or object for Lodash) and instead > return the default, so I think it is best to keep this behaviour I don't think that lodash is quite comparable here, because JavaScript is quite different to PHP in that *everything* is an object. Thus `_.get({"foo": "bar"}, "foo.length.toString")` is meaningful (namely it returns `Number.prototype.toString()`). As for the Laravel comparison, from what I see, they *do* support any `ArrayAccess`, so the function is also not comparable. I've also taken another look at the RFC and have the following additional comments: - The “Invalid array path segments” example is outdated, `stdClass` in the path should throw. - The types of the path-segments should be pre-validated for consistent error reporting. Meaning: array_path_get($array, ['foo', 'bar', new stdClass()]) should consistently throw, independent of whether `$array` is `[]`, `["foo" => []]`, `["foo" => ["bar" => []]` or something else. - I also wonder if `$path` should just be `string[]` instead of `(int|string)[]`. In the context of array keys, `"123"` is equivalent to `123` anyways. Best regards Tim Düsterhus