diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-08-11 14:28:10 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-08-11 14:28:10 +0200 |
commit | 228bae7d74a7886f05716ef5ac0f3ba200caccc4 (patch) | |
tree | f65b77d41e5c019ae6a14f997495adc113a47aab | |
parent | 4067519541850cfe47d031792f1d46829468706e (diff) | |
download | php-git-228bae7d74a7886f05716ef5ac0f3ba200caccc4.tar.gz |
Use TypeError for preg_replace type check
This is a type violation warning, and as such should use TypeError
in PHP 8.
-rw-r--r-- | ext/pcre/php_pcre.c | 4 | ||||
-rw-r--r-- | ext/pcre/php_pcre.stub.php | 4 | ||||
-rw-r--r-- | ext/pcre/tests/bug21732.phpt | 10 | ||||
-rw-r--r-- | ext/pcre/tests/preg_replace2.phpt | 6 | ||||
-rw-r--r-- | ext/pcre/tests/preg_replace_error2.phpt | 10 |
5 files changed, 17 insertions, 17 deletions
diff --git a/ext/pcre/php_pcre.c b/ext/pcre/php_pcre.c index 6002eedc78..4a603ec99d 100644 --- a/ext/pcre/php_pcre.c +++ b/ext/pcre/php_pcre.c @@ -2239,8 +2239,8 @@ static void preg_replace_common(INTERNAL_FUNCTION_PARAMETERS, int is_filter) } } else { if (Z_TYPE_P(regex) != IS_ARRAY) { - php_error_docref(NULL, E_WARNING, "Parameter mismatch, pattern is a string while replacement is an array"); - RETURN_FALSE; + zend_type_error("Parameter mismatch, pattern is a string while replacement is an array"); + return; } } diff --git a/ext/pcre/php_pcre.stub.php b/ext/pcre/php_pcre.stub.php index f4730f1b60..8a97cb4516 100644 --- a/ext/pcre/php_pcre.stub.php +++ b/ext/pcre/php_pcre.stub.php @@ -10,7 +10,7 @@ function preg_match_all(string $pattern, string $subject, &$subpatterns = null, * @param string|array $regex * @param string|array $replace * @param string|array $subject - * @return string|array|null|false + * @return string|array|null */ function preg_replace($regex, $replace, $subject, int $limit = -1, &$count = null) {} @@ -18,7 +18,7 @@ function preg_replace($regex, $replace, $subject, int $limit = -1, &$count = nul * @param string|array $regex * @param string|array $replace * @param string|array $subject - * @return string|array|null|false + * @return string|array|null */ function preg_filter($regex, $replace, $subject, int $limit = -1, &$count = null) {} diff --git a/ext/pcre/tests/bug21732.phpt b/ext/pcre/tests/bug21732.phpt index 3dfc41e19f..629e015a06 100644 --- a/ext/pcre/tests/bug21732.phpt +++ b/ext/pcre/tests/bug21732.phpt @@ -1,7 +1,5 @@ --TEST-- Bug #21732 (preg_replace() segfaults with invalid parameters) ---INI-- -error_reporting=0 --FILE-- <?php class foo { @@ -11,11 +9,15 @@ class foo { } } -var_dump(preg_replace('', array(), '')); +try { + var_dump(preg_replace('', array(), '')); +} catch (TypeError $e) { + echo $e->getMessage(), "\n"; +} var_dump(preg_replace_callback("/(ab)(cd)(e)/", array(new foo(), "cb"), 'abcde')); ?> --EXPECT-- -bool(false) +Parameter mismatch, pattern is a string while replacement is an array array(4) { [0]=> string(5) "abcde" diff --git a/ext/pcre/tests/preg_replace2.phpt b/ext/pcre/tests/preg_replace2.phpt index 4a191f3331..13696827fb 100644 --- a/ext/pcre/tests/preg_replace2.phpt +++ b/ext/pcre/tests/preg_replace2.phpt @@ -9,8 +9,6 @@ if (@preg_match('/./u', '') === false) { --FILE-- <?php -var_dump(preg_replace('', array(), '')); - var_dump(preg_replace(array('/\da(.)/ui', '@..@'), '$1', '12Abc')); var_dump(preg_replace(array('/\da(.)/ui', '@(.)@'), '$1', array('x','a2aA', '1av2Ab'))); @@ -21,9 +19,7 @@ var_dump(preg_replace(array('/\s+/', '~[b-d]~'), array('$'), array('x y', 'bd bc echo "==done==\n"; ?> ---EXPECTF-- -Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace2.php on line 3 -bool(false) +--EXPECT-- string(1) "c" array(3) { [0]=> diff --git a/ext/pcre/tests/preg_replace_error2.phpt b/ext/pcre/tests/preg_replace_error2.phpt index a334b2fefd..0a3ba3bb46 100644 --- a/ext/pcre/tests/preg_replace_error2.phpt +++ b/ext/pcre/tests/preg_replace_error2.phpt @@ -16,7 +16,11 @@ $replace = array('this is a string', array('this is', 'a subarray'),); $subject = 'test'; foreach($replace as $value) { print "\nArg value is: $value\n"; - var_dump(preg_replace($regex, $value, $subject)); + try { + var_dump(preg_replace($regex, $value, $subject)); + } catch (TypeError $e) { + echo $e->getMessage(), "\n"; + } } $value = new stdclass(); //Object try { @@ -33,8 +37,6 @@ Arg value is: this is a string string(64) "this is a stringthis is a stringthis is a stringthis is a string" Arg value is: Array - -Warning: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array in %spreg_replace_error2.php on line %d -bool(false) +Parameter mismatch, pattern is a string while replacement is an array Object of class stdClass could not be converted to string Done |