Skip to content

Commit

Permalink
Deprecate explicit use of FILTER_FLAG_SCHEME|HOST_REQUIRED
Browse files Browse the repository at this point in the history
As of PHP 5.2.1 FILTER_VALIDATE_URL implies FILTER_FLAG_SCHEME_REQUIRED
| FILTER_FLAG_HOST_REQUIRED, which makes these constants useless at
best, if not even misleading.  Therefore we deprecate the explicit use
of these constants for FILTER_VALIDATE_URL, to pave the way for their
eventual removal.

See <https://wiki.php.net/rfc/deprecations_php_7_3#filter_flag_scheme_required_and_filter_flag_host_required>.
  • Loading branch information
cmb69 committed Jul 17, 2018
1 parent ffa4178 commit c0407d9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ext/filter/logical_filters.c
Expand Up @@ -539,6 +539,11 @@ void php_filter_validate_url(PHP_INPUT_FILTER_PARAM_DECL) /* {{{ */
php_url *url;
size_t old_len = Z_STRLEN_P(value);

if (flags & (FILTER_FLAG_SCHEME_REQUIRED | FILTER_FLAG_HOST_REQUIRED)) {
php_error_docref(NULL, E_DEPRECATED,
"explicit use of FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED is deprecated");
}

php_filter_url(value, flags, option_array, charset);

if (Z_TYPE_P(value) != IS_STRING || old_len != Z_STRLEN_P(value)) {
Expand Down
19 changes: 19 additions & 0 deletions ext/filter/tests/deprecated.phpt
@@ -0,0 +1,19 @@
--TEST--
FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED are deprecated
--SKIPIF--
<?php
if (!extension_loaded('filter')) die('skip filter extension not available');
?>
--FILE--
<?php
var_dump(filter_var('//example.com/', FILTER_VALIDATE_URL, FILTER_FLAG_SCHEME_REQUIRED));
var_dump(filter_var('http://', FILTER_VALIDATE_URL, FILTER_FLAG_HOST_REQUIRED));
?>
===DONE===
--EXPECTF--
Deprecated: filter_var(): explicit use of FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED is deprecated in %s
bool(false)

Deprecated: filter_var(): explicit use of FILTER_FLAG_SCHEME_REQUIRED and FILTER_FLAG_HOST_REQUIRED is deprecated in %s
bool(false)
===DONE===

0 comments on commit c0407d9

Please sign in to comment.