Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130581 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 9D6071A00BD for ; Mon, 6 Apr 2026 16:09:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1775491774; bh=gka3R/XoAONak86KBHviQetKdgZS/sdZmAyfr6PCO4Q=; h=Date:From:To:In-Reply-To:References:Subject:From; b=Q/LtiKgHFFoAoWqHVD4PAwFwL+4GPiluQ6FumbnSIJ9AUZUHFbbpKRY4cgXcxcN7h as13VnR4IpU9mNTDwQ5HO5Iha8ZU3BPFAlTkVKzoaV/UxImUf12w8HU3oRPLgM9S5i Up5+fHGdCDFaAnU2BJ+4kGcRSU+Apjph4vCPen7YIo+uE8Y6CAqd7LTlem+vm9HApG Je24on8kbfqiWUVHbxt+8DxcU6ExxM6gB1vdRXj+C9NFdKqcP5ZFj/by7qWdpL6da+ q17UeVjdroOqt89uD7qp+u2ih9MQwFx3akL4yGOrpmHePaR3m6VzeBGACNk0s+R4ES EQbAMqZLiyAXQ== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id B98101801D8 for ; Mon, 6 Apr 2026 16:09:31 +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.1 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_MISSING,RCVD_IN_DNSWL_LOW, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=4.0.1 X-Spam-Virus: No X-Envelope-From: Received: from fhigh-b7-smtp.messagingengine.com (fhigh-b7-smtp.messagingengine.com [202.12.124.158]) (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 16:09:29 +0000 (UTC) Received: from phl-compute-04.internal (phl-compute-04.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id DA5DE7A0209 for ; Mon, 6 Apr 2026 12:09:23 -0400 (EDT) Received: from phl-imap-02 ([10.202.2.81]) by phl-compute-04.internal (MEProxy); Mon, 06 Apr 2026 12:09:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= garfieldtech.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to; s=fm2; t=1775491763; x=1775578163; bh=JZG3kmEyPkZAfm1RkPprh Ee4/LejgQ2VznwzWG9KThI=; b=WRX+xy6ksvM4bPA95BD0n7fVeq8Ls3HoAi7ye cB+88lpwAtaguuJyzjvEOwB1c5QT/U+aWQ+r5KwlqGaW0TFivgop5ICJUtAwKjLG 6HM5vewnS9yuiK7Uv3LN4G3f0xsbqCc6+Otxl3hVp9xsEwt17DRajySk18IfHVML 1arzArITZzT7Ib+IOrlRK5IY7gVGKdpFOc46mZlyjuvlJ99OjwX8ucUxN5XFrfYI zbOJM5E2jW2ZRcCZ9wJYG1EtjqpxCz1oQ/bHVZByfPss6dX9nucC6VoQkQ2C5drK MbghcYZnshp5Wz69Nk971ifbjaU67UnZu95bh/f4M0e9Fapug== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; t=1775491763; x=1775578163; bh=J ZG3kmEyPkZAfm1RkPprhEe4/LejgQ2VznwzWG9KThI=; b=rwks/3KWCkkMr71T/ DHMAd76mKv6y39DxmosMg3ZhFA63VvP7AeWQqMInG5CaWTh/BcFDNqkUTYBAvqku tM9t9wdKVjsmFAJrrNvn0brgp0So/XZy8iaQ7UJ3YYTcuPHGwsa1j0pUGhzZaBkX soWFn3ntZ+BcZJONuOm6aIFuVWhH+5XCMNN6vz3TM50jvq6dGOHRlSFUtYLurLzz FMaCNlmuANqKxijoIciFc0OtdEgH1fiZRsf55NqrzMCJCKHOsYAjSs8ex6z6Zorj 5lF8X0q6Y1RzWwgb5JVepJ/uLhtwoRYCFEaMHZolP/bEQvul4heNGzxPIdqbOWZz XChfg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddukedujecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpuffrtefokffrpgfnqfghnecuuegr ihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjug hrpefoggffhffvkfgjfhfutgfgsehtjeertdertddtnecuhfhrohhmpedfnfgrrhhrhicu ifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtghomheqne cuggftrfgrthhtvghrnhepudegvdelgfeugeehfeejteffudevleethfefgeejffffleeg tddtveekgeekudfgnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilh hfrhhomheplhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhmpdhnsggprhgtphht thhopedupdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehinhhtvghrnhgrlhhsse hlihhsthhsrdhphhhprdhnvght X-ME-Proxy: Feedback-ID: i8414410d:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 68452700065; Mon, 6 Apr 2026 12:09:23 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 X-ThreadId: AwW8RH0VV87o Date: Mon, 06 Apr 2026 11:09:03 -0500 To: "php internals" Message-ID: <1b1eb4f5-4701-4ccb-94b7-42306c3f33b5@app.fastmail.com> In-Reply-To: References: <1775385960072.803756451.2349920337@yahoo.de> Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions Content-Type: text/plain Content-Transfer-Encoding: 7bit From: larry@garfieldtech.com ("Larry Garfield") On Mon, Apr 6, 2026, at 10:01 AM, Barel wrote: > 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 change > > Cheers > > Carlos Please remember to bottom post. :-) It looks like the RFC hasn't been fully updated for array-based "keys" yet. The function signatures in most of the examples still say string|int|null. Despite my long-standing and public crusade against arrays being used where an object belongs, I'm overall in favor of this direction. However, I would go all-in on the array syntax, not the dotted syntax. There's a few reasons for that. 1. The various notes around escaping. Having a string instruction format that doesn't handle escaping and encoding and other edge cases is asking for trouble, and it's trouble that will be harder to fix in the future. String instructions are always more complicated and nuanced than you expect, so a simple "split on the dot and now it's an array!" approach is just too rudimentary to be trustworthy, for all the reasons mentioned in previous posts. 2. If you're not building the path dynamically, then there is little advantage of it over what we have now. array_get($array, 'foo.bar.1.baz', null); $array['foo']['bar'][1]['baz'] ?? null The second may be slightly slower to type because of the punctuation, but it's perfectly viable today. Where it becomes interesting is when the path is variable... and if the path is variable, I'll probably want to be building it dynamically rather than just selecting one of a few hard-coded options. And if I'm building it dynamically, then string concatenation is an awful way to do that, for all the escaping reasons mentioned previously. We're back to concatenating SQL strings together, with all the risk that entails. So I would be in favor of going all the way to function array_get(array $array, array $path, mixed $default = null) {} Or, for that matter, that is nearly the same as: function array_get(array $array, array $path) {} array_get($arr, $path) ?? null; Which would allow using a variadic for the $path if desired, instead of an array. I'm not certain that's optimal, but I think it's worth discussing. array_has() would then follow suit. Then, separately, I would be in favor of a full-on JSON Pointer implementation that can work on both arrays and JSON blobs, potentially (as the two are effectively isomorphic). Skip a custom dot notation. Go straight to the fully robust standard. Do not pass go, do not collect 200 security reports. --Larry Garfield