|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78385 parse_url() does not include 'query' when question mark is the last char
Submitted: 2019-08-07 21:57 UTC Modified: -
From: benjamin dot morel at gmail dot com Assigned:
Status: Closed Package: *URL Functions
PHP Version: 7.3.8 OS: N/A
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: benjamin dot morel at gmail dot com
New email:
PHP Version: OS:


 [2019-08-07 21:57 UTC] benjamin dot morel at gmail dot com
parse_url() returns the same result for these 2 distinct URLs:

In the first URL, there is no query string, so the 'query' key is not set. This is OK. In the second URL, there is one, an empty one. As such, PHP should set the 'query' key in the result array to an empty string. At the moment, it's unset.

The issue with the current implementation is that libraries that parse and build URLs cannot differentiate these two, and will build a URL that's different from the parsed one.

Another issue is for libraries handling robots.txt files. According to Google (see, the following rule:

Disallow: /*.php$

... will match '/filename.php', but not '/filename.php?'.

If I'm using parse_url() to extract the path and query string from the full URL, I will not be able to differentiate the two URLs above.

Test script:


var_export(parse_url('', PHP_URL_QUERY));

Expected result:
array (
  'scheme' => 'http',
  'host' => '',
  'path' => '/foo',
  'query' => '',


Actual result:
array (
  'scheme' => 'http',
  'host' => '',
  'path' => '/foo',



Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-01-11 15:35 UTC] israfilov93 at gmail dot com
The following pull request has been associated:

Patch Name: ticket-78385 an empty string in parse_url() return when question markā€¦
On GitHub:
 [2020-01-13 09:18 UTC]
Automatic comment on behalf of
Log: Fixed #78385: Distinguish absent/empty query/fragment
 [2020-01-13 09:18 UTC]
-Status: Open +Status: Closed
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Feb 26 12:01:26 2024 UTC