From 37c11250394ab5b1a81cb6ffb8a0d97990710b35 Mon Sep 17 00:00:00 2001 From: George Peter Banyard Date: Thu, 22 Aug 2019 12:33:46 +0200 Subject: [PATCH] Promote warnings to errors in strtr() --- ext/standard/string.c | 6 +- .../tests/strings/strtr_variation8.phpt | 77 ++++++------------- 2 files changed, 28 insertions(+), 55 deletions(-) diff --git a/ext/standard/string.c b/ext/standard/string.c index c2f29baec7732..edecd0c28a35a 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 8d29db1cc3afc..2e2843335d477 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 ***