Doc #75442 [NEW]: SCHEME and HOST VALIDATE_URL constants are not actually used
From: wrossmann at gmail dot com
Operating system:
PHP version: Irrelevant
Package: Filter related
Bug Type: Documentation Problem
Bug description:SCHEME and HOST VALIDATE_URL constants are not actually used
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)
--
Edit bug report at https://bugs.php.net/bug.php?id=75442&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75442&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75442&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75442&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=75442&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=75442&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=75442&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=75442&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=75442&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=75442&r=support
Expected behavior: https://bugs.php.net/fix.php?id=75442&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=75442&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=75442&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=75442&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75442&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=75442&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=75442&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=75442&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=75442&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=75442&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=75442&r=mysqlcfg
Thread (2 messages)
- wrossmann at gmail dot com