On Fri, Oct 7, 2016 at 2:22 PM, Stephen Reay <step...@koalephant.com> wrote:

> I think adopting the JavaScript model here is not an improvement.
>
> One of the strengths of parse_url is that it can parse a partial url and
> give the parts that are found. How do we achieve the same using the whatwg
> concept where relative URLs *require* a base url, besides using
> fake://fakey.mcfakeface/fakes?faking#faker as the base url?
>

This strength of parse_url is also its weakness. In the FastRoute README I
used to recommend that people use parse_url() to extract the path component
of REQUEST_URI. It turns out that while this works for 99% of URLs it will
fail in specific edge-cases, such as paths starting with more than one
slash. To get correct behavior you either need to strip the query string
yourself, or use parse_url() with an artificial prefix (which is the
equivalent of your suggestion).


> Also, the browser implementations specifically *dont* handle parsing of
> the query string into a usable structure. So would we then need to create a
> url object and pass it's query property to parse_str to get a useful value?
>

parse_url() doesn't handle this either. For the record, the URL spec does
handle this in the form of URLSearchParams, but this is likely not directly
transferable to PHP, because PHP interprets query strings differently.


> I'm not against OO, I would just rather that if it goes that way, a solid
> implementation is used, because simply copying what's used in JavaScript
> sounds like a decision that will be regretted down the track.
>

To be clear, the URL API is not some legacy API that JS is stuck with for
historic reasons. It's a relatively new addition to the point that MDN
marks it as "experimental". I'm not saying that it's necessarily best to
directly copy it (I'm not sufficiently familiar with the subject matter),
but I do suspect that they have put significantly more thought into this
than we have.

Nikita

Reply via email to