Skip to content

Promote warnings to errors in strtr() #4606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ext/standard/string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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 */
Expand Down
77 changes: 25 additions & 52 deletions ext/standard/tests/strings/strtr_variation8.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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 ***