php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75442 Remove FILTER_FLAG_SCHEME|HOST_REQUIRED constants
Submitted: 2017-10-25 21:24 UTC Modified: 2018-07-17 11:09 UTC
Votes:5
Avg. Score:3.4 ± 1.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: wrossmann at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Filter related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-10-25 21:24 UTC] wrossmann at gmail dot com
Description:
------------
Commit: https://github.com/php/php-src/commit/ea491dba64d6c15a515e0f1cc58d881c2e2dc2f3#diff-a61ab806f8c2193851acdd3eb5f37232L489

Regarding bug: https://bugs.php.net/bug.php?id=39898

The above patch essentially removed the only usage of the constants FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_SCHEME_REQUIRED, however the constants themselves not only still exist, but the documentation's only hint about this is the changelog note: 5.2.1 FILTER_VALIDATE_URL now defaults to FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED.

The phrasing of this, and the continued presence of these constants, is misleading in that the word 'default' implies that it can be changed to something else, which it frankly cannot. Furthermore, there's no '_DEFAULT' flag against which one would expect to negate whatever defaults are supposedly enabled, hence the explicit 0 in the test script.

I suggest at least amending the doc page to better convey to users that the VALIDATE_URL filter *requires* both scheme and host since 5.2.1, and that those constants have no effect.

At some point I'd wager that these now-useless constants should be removed entirely, but doing so would be a potential BC break so I guess that would have to wait for PHP8.

Test script:
---------------
$no_scheme = '//google.com/foo/bar';
$no_host   = '/foo/bar';

var_dump(
    $no_scheme,
    parse_url($no_scheme),
    filter_var("$no_scheme",FILTER_VALIDATE_URL, 0)
);

var_dump(
    $no_host,
    parse_url($no_host),
    filter_var("$no_host",FILTER_VALIDATE_URL, 0)
);


Expected result:
----------------
No scheme:
string(20) "//google.com/foo/bar"
array(2) {
  ["host"]=>
  string(10) "google.com"
  ["path"]=>
  string(8) "/foo/bar"
}
bool(true)

No host:
string(8) "/foo/bar"
array(1) {
  ["path"]=>
  string(8) "/foo/bar"
}
bool(true)

// note: this would only be the expected result if the functionality matched the documentation.

Actual result:
--------------
No scheme:
string(20) "//google.com/foo/bar"
array(2) {
  ["host"]=>
  string(10) "google.com"
  ["path"]=>
  string(8) "/foo/bar"
}
bool(false)

No host:
string(8) "/foo/bar"
array(1) {
  ["path"]=>
  string(8) "/foo/bar"
}
bool(false)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-10-28 15:11 UTC] cmb@php.net
-Status: Open +Status: Verified -Assigned To: +Assigned To: cmb
 [2017-10-28 15:41 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=343324
Log: Fix bug #75442: SCHEME and HOST VALIDATE_URL constants are not actually used
 [2017-10-28 15:43 UTC] cmb@php.net
-Summary: SCHEME and HOST VALIDATE_URL constants are not actually used +Summary: Remove FILTER_FLAG_SCHEME|HOST_REQUIRED constants -Status: Verified +Status: Open -Type: Documentation Problem +Type: Feature/Change Request
 [2017-10-28 15:43 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

I'm switching to feature request wrt. removing the unused constants.
 [2017-10-28 16:24 UTC] cmb@php.net
See <https://externals.io/message/100981>.
 [2018-07-17 11:09 UTC] cmb@php.net
-Status: Assigned +Status: Closed
 [2018-07-17 11:09 UTC] cmb@php.net
These flags are deprecated as of PHP 7.3.0 and will be removed in
PHP 8, according to
<https://wiki.php.net/rfc/deprecations_php_7_3#filter_flag_scheme_required_and_filter_flag_host_required>.
 [2020-02-07 06:06 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=8ac7e3e35e5405bd7f07c42401b3e7199c0d0acf
Log: Fix bug #75442: SCHEME and HOST VALIDATE_URL constants are not actually used
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 19 00:01:29 2024 UTC