Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130676 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 BC81C1A00BC for ; Mon, 20 Apr 2026 17:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1776704703; bh=NMN/toWOehdlOZ3H9YzyMsjmHpJZaZcDfjuAfyuTs24=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=aIdzSynt6QPGgliE0/Lk36cKFO9Gy8M5MHWbNVAsgBG55bV+CgpV3O+N3zGTmEXf8 CEV8v656++qU98jdh/L34Np28VbTkqn108XhRuYWBiY+DNn+525Xpwk9bd3VCpXiTr GtkcJF15C9siGsWooZLyHXf/04aE03lZ3XyzA0pjgS+ODg+anMwS2mcl3kuDjbcAIl yaxRsLQkN0spo96C2XCFbM3mQcK0kn9Da776TycZkMHIEv+zMa+nt1JvEYm3gk6qeV ZSZMVqqgY8wdMZ1RshnFRA7vs871MyxN6VyU1YiEvF0UpqW1LEIGIa2KqdeppmLfDm tow4ZzIovv85g== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 73A441801E3 for ; Mon, 20 Apr 2026 17:05:02 +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 ; Mon, 20 Apr 2026 17:05:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1776704695; bh=kbLlfVtZVpj6dMCNZWndq+3JtiT0ju/i/anWqhjynfo=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type:from:to:cc:subject:message-id; b=ZxOQ4wFk3jwyfzTWGZL4JkKg7v5BopceXNVJq6znEJw/9052z0abXOnybHTjO+b1K u/bTfl+Dl1MVLI4t5Xd3gcncBIcfsuMQzzEDTXkzeUZSuBUM52Xma7j1wV7CQlgKPG cxa2NcCuPVyXSMSS86BPcwXqNG5xw1FC4QAMYoTDlsySAfVUR6RJGjhc7YqERL5BKt KYEPMEnsXlf2oTDqU0EUYfBAdAQvVWyjUYvhpd4xaEwbaZsnl7U4ZcTC3fgZkDxYn0 3lXBoay8ZJXv1uXkiioQjvWlKZ8xlLLZ9sfdvuIa8DPFAlL1p/KHZyrztdKM/hsfbQ 4iHDdg32+WWeA== Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Date: Mon, 20 Apr 2026 19:04:55 +0200 To: Larry Garfield Cc: php internals Subject: Re: [PHP-DEV] [RFC] [Discussion] array_get and array_has functions In-Reply-To: <8dca7d45-fce4-4d6a-ac56-956046ef20a6@app.fastmail.com> References: <19d58a46b50222b75da4e40e417efd05@bastelstu.be> <4f684a4fbad3a7ddb797e24e3c1a882a@bastelstu.be> <8dca7d45-fce4-4d6a-ac56-956046ef20a6@app.fastmail.com> Message-ID: 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-20 17:18, schrieb Larry Garfield: > Just to make sure we're talking about the same thing here. Tim, you're > suggesting that this: > > $a = ['foo' => 'bar']; > $val = array_path_get($a, ['foo', 'bar', 'baz']); > > Should error rather than returning null? Yes. > If the array were clearly, consistently, and properly structured, we > could reliably just do $a['foo']['bar'] and move on with life. > […] > So in that sort of case, I'm not sure it's useful to distinguish > between "There is no baz key on the array at foo.bar" and "foo.bar is a > string, not an array, wat?" […] The goal of the RFC is replacing `$a['foo']['bar']` where the *path is dynamic*. Quoting right from the introduction of the RFC: > When the structure of the array is known in advance and the exact > element to retrieve is hardcoded, existing PHP syntax works well […] And quoting further from the introduction: > array_path_get() retrieves a value from a deeply nested array and > returns a default value if the path does not exist. I'm arguing that a “(value at) path does not exist” is something fundamentally different from “value encountered on path cannot be traversed further”. > converting to an object I agree that the correct solution in the general case is “use a proper object mapper” (such as Valinor) and don't see much personal value in having the proposed functions. But if they exist, I would want them to behave as safely as possible and that includes erroring if they cannot make sense of the data. Emitting a Warning when encountering an improperly typed value across the path would also work for me, but I suppose that others won't be in favor of *that* :-) Best regards Tim Düsterhus