com php-src: Promote warnings to errors in strtr(): ext/standard/string.c ext/standard/tests/strings/strtr_variation8.phpt
| From: | George Peter Banyard | Date: | Thu, 22 Aug 2019 17:33:37 +0000 |
| Subject: | com php-src: Promote warnings to errors in strtr(): ext/standard/string.c ext/standard/tests/strings/strtr_variation8.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-107991@lists.php.net to get a copy of this message | ||
Commit: c0554fdec5a73f34472fdcf082179ae4895c903d
Author: George Peter Banyard <girgias@php.net> Thu, 22 Aug 2019 12:33:46 +0200
Parents: c1fcf2d616d2c54d13be6daa6dc31f23160de636
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=c0554fdec5a73f34472fdcf082179ae4895c903d
Log:
Promote warnings to errors in strtr()
Changed paths:
M ext/standard/string.c
M ext/standard/tests/strings/strtr_variation8.phpt
Diff:
diff --git a/ext/standard/string.c b/ext/standard/string.c
index c3e9660..e8a8fed 100644
--- a/ext/standard/string.c
+++ b/ext/standard/string.c
@@ -3292,7 +3292,7 @@ PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const
ch
}
/* }}} */
-/* {{{ proto string|false strtr(string str, string from[, string to])
+/* {{{ proto string strtr(string str, string from[, string to])
Translates characters in str using given translation tables */
PHP_FUNCTION(strtr)
{
@@ -3310,8 +3310,8 @@ PHP_FUNCTION(strtr)
ZEND_PARSE_PARAMETERS_END();
if (ac == 2 && Z_TYPE_P(from) != IS_ARRAY) {
- php_error_docref(NULL, E_WARNING, "The second argument is not an array");
- RETURN_FALSE;
+ zend_type_error("The second argument is not an array");
+ return;
}
/* shortcut for empty string */
diff --git a/ext/standard/tests/strings/strtr_variation8.phpt
b/ext/standard/tests/strings/strtr_variation8.phpt
index 8d29db1..2e28433 100644
--- a/ext/standard/tests/strings/strtr_variation8.phpt
+++ b/ext/standard/tests/strings/strtr_variation8.phpt
@@ -75,10 +75,15 @@ $replace_pairs_arr = array (
// loop through with each element of the $replace_pairs array to test strtr() function
$count = 1;
for($index = 0; $index < count($replace_pairs_arr); $index++) {
- echo "\n-- Iteration $count --\n";
- $replace_pairs = $replace_pairs_arr[$index];
- var_dump( strtr($str, $replace_pairs) );
- $count ++;
+ echo "\n-- Iteration $count --\n";
+ $replace_pairs = $replace_pairs_arr[$index];
+ try {
+ var_dump( strtr($str, $replace_pairs) );
+ } catch (\TypeError $e) {
+ echo $e->getMessage() . "\n";
+ }
+
+ $count ++;
}
fclose($file_handle); //closing the file handle
@@ -89,34 +94,22 @@ echo "*** Done ***";
*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***
-- Iteration 1 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 2 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 3 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 4 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 5 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 6 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 7 --
string(6) "012atm"
@@ -128,52 +121,32 @@ string(6) "012atm"
string(6) "122atm"
-- Iteration 10 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 11 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 12 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 13 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 14 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 15 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 16 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 17 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 18 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
-- Iteration 19 --
-
-Warning: strtr(): The second argument is not an array in %s on line %d
-bool(false)
+The second argument is not an array
*** Done ***