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

Reply via email to