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

From: Date: Sun, 27 Apr 2025 21:05:37 +0000
Subject: Re: [RFC] [Discussion] Add WHATWG compliant URL parsing API
References: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

On 4/27/25 22:50, ignace nyamagana butera wrote:
I understand that but then I fail to see the added value of the parse method vs the default constructor since from the RFC the only difference is that the parse named constructor should instead of throwing return null. If the parse method can still throw from a consumer POV it looses much of it's utility. If I really want that level of knowledge using the constructor should be the only way to go AFAIK. Since the $baseUri is a known existing URI, I expect it to be always be valid, otherwise it would be a programming error. The (relative) $uri is the bit that comes from an untrusted source. Handling both cases by returning null would make the API much worse, since it is no longer clear which of the values is invalid.
Perhaps as a solution, it would make sense to change the signature to:
    (string $uri, ?self $baseUri = null)
instead to enforce that the $baseUri must be valid. This might also improve performance, by allowing to avoid repeatedly parsing the $baseUri, e.g. when bulk processing a number of relative links. Best regards Tim Düsterhus

Thread (152 messages)

« previous php.internals (#127213) next »