Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:130376 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 BD6981A00BC for ; Mon, 16 Mar 2026 21:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1773695111; bh=jmGDIIgxQFMtlVT1jlfTNggtE6CDXkHAKjC3vWupvK0=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=NAbTMoCt46w/Poh3Kv9EKOB/4Kz39RSADg8kyBlfZp/SxsV8aWnOE8or0jvCwoarl 1sbwrCo6/INu0BaTKzM5C2ueVlWKtE7xNHlriGAgUU607RHKt9NG3gRmFm+SzPwGoI v1YYJheGi71N950YaTEC10N3rKpYkm+LIx4BD1JRa7QHVLPqNEf16mfg/U8iyiPXfV W14fZhFg6E1kp9wsqf9AeIg/g3xjtRIYYtchBrRQu43+Bnnc7WaZKYlKgxLvORVLie pIDwMAUlwjelJ3VLRXVffW06/WlZ+eXTposP8FJCdSO1lUOj/csJFksKwO5Z7NKWwn Ru635hHNfEXmA== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CBA9A18038A for ; Mon, 16 Mar 2026 21:05:06 +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, T_SPF_TEMPERROR 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, 16 Mar 2026 21:05:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bastelstu.be; s=mail20171119; t=1773695099; bh=89FGpaAkd0gvGPORY4EuiOqNPfuigTUaVSQr8IEuK6A=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type:from:to:cc:subject:message-id; b=UKxDX7qqDgKx3e60f0tMLFvdY1o1LqBfB8uUgg9b1SFt7NOXEtOvUpvbbt3a6PtWA 9zC2eXVPBaX04YG9URDFqfBHHd4jIYQse5Ts50Ubg+VRZiaZ9V6WgDpONr4EyD1Xi4 gWCn8oXXB8W2qDFRxici9myWLPD/vMj+JPTsLcQkx+bRdUcTrsuXsnDNXS3zuHLbX0 U+u26sbCKlBRlBbRm/5u7JzSSwv3AIiYfhtpMJH1hdGgsjg12WFXC6DgxWXKLyy03a aZPuMdvG2OBgGM+umEWq2neXDbAuzjTZu93xE7TGqZsYz5tTdz1jxZIdNspKVSMOu0 hrmIG4OWaGvjA== Message-ID: <72527aaa-237a-411e-a885-a341f4725b54@bastelstu.be> Date: Mon, 16 Mar 2026 22:04:57 +0100 Precedence: list list-help: list-unsubscribe: list-post: List-Id: x-ms-reactions: disallow MIME-Version: 1.0 Subject: Re: [PHP-DEV] [RFC] [Discussion] Query Parameter Manipulation Support To: =?UTF-8?B?TcOhdMOpIEtvY3Npcw==?= Cc: PHP Internals List References: Content-Language: en-US In-Reply-To: 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 On 3/9/26 21:47, Máté Kocsis wrote: > Same situation as above, but basically the whole section is a big question > mark: > I couldn't come up with a good enough idea how arrays could be handled > efficiently and ergonomically, and in the same time, how to (mostly) conform > to WHATWG URL. The internal storage should not know about arrays. It should represent things as a list of key-value pairs, with arrays only being materialized for the methods that are intended to deal with arrays. Given that the class is generic, matching the WHATWG API 1:1 is not necessary in my opinion. > Some of my problems: > - How should $params->get("foo[bar]") behave? Should we try to parse the > supplied key as an array and return the > nested item if it exists? I suppose, we would internally store the query > params as an array (just like how $_GET does), > so then we would definitely need parsing in order to be able to return item > "bar" stored within array "foo". `->get()` does not currently exist within the RFC. The WHATWG `get()` is equivalent to `->getFirst()`. > - However, what should a $params->append("foo[bar]") call do when the query > param "foo" is already added with a string value? > Should it modify the existing item to be an array (but then how?) or we > should just add "foo[bar]" to the query params as-is? It should add `foo[bar]` as-is. `foo` and `foo[bar]` are different keys. The square-bracket syntax is something that is specific to PHP. > - How to recompose list parameters? Ideally, we should not append [] to > these parameters (e.g. The recomposition should be "dumb" and just use the keys as-is. The complex logic should happen in the getter or setter. Only the 'array' getters and setters deal with the PHP-specific square-bracket syntax. To give an example: "k=1&k=2" [['k', '1'], ['k', '2']] getAll('k') // ['1', '2'] getArray('k') // UriException: 'k' is not an array. "k[]=1&k[]=2" [['k[]', '1'], ['k[]', '2']] getAll('k') // [] getAll('k[]') // ['1', '2'] getArray('k') // ['1', '2'] "k[a]=1&k[b]=2" [['k[a]', '1'], ['k[b]', '2']] getAll('k') // [] getAll('k[a]') // ['1'] getArray('k') // ['a' => '1', 'b' => '2'] "k=1&k[]=2" [['k', '1'], ['k[]', '2']] getAll('k') // ['1'] getAll('k[]') // ['2'] getArray('k') // UriException: 'k' is not an array. "k[]=2&k=3"; [['k[]', '2'], ['k', '3']]; getAll('k') // ['3'] getAll('k[]') // ['2'] getArray('k') // UriException: 'k' is not an array. The string should internally be represented something like the arrays and the getters should work as indicated in the comment. And then for the setters: // [] append('k', '1') // [['k', '1']] append('k', '2') // [['k', '1'], ['k', '2']] append('k[]', '3') // [['k', '1'], ['k', '2'], ['k[]', '3']] set('k', '4') // [['k[]', '3'], ['k', '4']] The `setArray()` method would then create a number of entries with square brackets added as appropriate (and delete all entries that would be returned by `getArray()`). The `appendArray()` method should probably be dropped to avoid issues with "mixing non-array with array keys". So: // [] setArray('k', ['1']) // [['k[]', '1']] setArray('k', ['1', '2']) // [['k[]', '1'], ['k[]', '2']] setArray('k', ['a' => '1', '2']) // [['k[a]', '1'], ['k[0]', '2']] append('k', 'x') // [ // ['k[a]', '1'], // ['k[0]', '2'], // ['k', 'x'], // ] setArray('k', ['1']) // [['k[]', '1']] Does that make sense? Best regards Tim Düsterhus