Re: [RFC] [Discussion] Add WHATWG compliant URL parsing API

From: Date: Sun, 30 Jun 2024 06:51:52 +0000
Subject: Re: [RFC] [Discussion] Add WHATWG compliant URL parsing API
References: 1 2  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
On 29/06/2024 11:57, Stephen Reay wrote:
On 29 Jun 2024, at 04:48, Niels Dossche <[email protected]> wrote: - It's a bit of a shame that the PSR interface treats queries as strings. In Javascript we have the URLSearchParams class that we can use as a key-value storage for query parameters. This Javascript class also handles escaping them nicely.
Agreed this is a weird choice to me, but I'm also not surprised by weird choices via php-fig (log level constants I'm looking at you) We hear all the time how userland is more flexible and can change quicker - and yet here we see a potential built in class having a worse api because it wants to be compatible with an existing userland interface with the same bad api.... Cheers Stephen
While I do not think the debate should be about compatibility with PSR-7 some historical context shoyld be brought to light for a fair discussion: - parse_url and parse_str predates RFC3986 - URLSearchParans was ratified before PSR-7 BUT the first implementation landed a year AFTER PSR-7 was released and already implemented. - PHP historical query parser parse_str logic is so bad (mangled parameter name for instance) that PSR-7 was right not embedding that parsing algorithm in its specification. - If you take aside URITemplate specification and now URLSearchParams there is no official, referenced and or agreed upon rules/document on how a query string MUST or SHOULD be parsed. - Last but not least URLSearchParans encoding/decoding rules DO NOT follow either RFC1738 nor RFC3986 (they follow the form data which is kind of a mix between both RFC) THis means that just adding a method or a class that mimic 100% URLSearchParans for instance will constitute a major departure in how PHP trears query string you will no longer have a 1:1 relation between the data you have inside your _GET array and the one in UrlSearchParams for better or for worse. For all these arguments I would keep the proposed Url free of all these concerns and lean toward a nullable string for the query string representation. And defer this debate to its own RFC regarding query string parsing handling in PHP.

Thread (152 messages)

« previous php.internals (#124077) next »