|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43721 parse_url does not handle "protocol relative" URLs
Submitted: 2007-12-31 18:10 UTC Modified: 2007-12-31 21:27 UTC
From: phpbugs at thequod dot de Assigned:
Status: Not a bug Package: URL related
PHP Version: 5.2.5 OS: Ubuntu Linux
Private report: No CVE-ID: None
 [2007-12-31 18:10 UTC] phpbugs at thequod dot de
parse_url does not parse "protocol relative" URLs correctly.

"protocol relative" URLs start with to slashes, leaving the "proto:" 
part out.

parse_url should parse them like a "http://" url, but leave 
the "protocol" key unset, as far as I can see.

See RFC3986.

Reproduce code:
$ php -r '$p = parse_url("//"); var_dump($p);'

Expected result:
array(2) {
  string(11) ""
  string(17) "/bar"

Actual result:
array(1) {
  string(17) "//"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-12-31 21:27 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

That's expected, because unless a protocol is specified, it assumes 
 [2013-01-24 09:13 UTC] victor dot sollerhed at gmail dot com
I think this actually is a bug. Could this please be re-opened?

"A relative URL without a scheme (http: or https:) is valid, per RFC 3986: 
"Uniform Resource Identifier (URI): Generic Syntax", Section 4.2. If a client 
chokes on it, then it's the client's fault because they're not 
complying with the URI syntax specified in the RFC."

Please see:
 [2013-09-22 17:30 UTC] yastrakhan at wikimedia dot org
I also think this is a very unintuitive behavior - protocol-relative URLs are very common, while the file:// has very limited and archaic use. parse_url() should behave very similar to modern browsers.
 [2014-01-10 11:10 UTC] bluemoehre at gmx dot de
Today i had to build a workaround for that. This behaviour is unexpected and should be changed.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Jun 16 21:01:29 2024 UTC