Skip to content

Commit c0554fd

Browse files
committed
Promote warnings to errors in strtr()
1 parent c1fcf2d commit c0554fd

File tree

2 files changed

+28
-55
lines changed

2 files changed

+28
-55
lines changed

ext/standard/string.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3292,7 +3292,7 @@ PHPAPI zend_string *php_str_to_str(const char *haystack, size_t length, const ch
32923292
}
32933293
/* }}} */
32943294

3295-
/* {{{ proto string|false strtr(string str, string from[, string to])
3295+
/* {{{ proto string strtr(string str, string from[, string to])
32963296
Translates characters in str using given translation tables */
32973297
PHP_FUNCTION(strtr)
32983298
{
@@ -3310,8 +3310,8 @@ PHP_FUNCTION(strtr)
33103310
ZEND_PARSE_PARAMETERS_END();
33113311

33123312
if (ac == 2 && Z_TYPE_P(from) != IS_ARRAY) {
3313-
php_error_docref(NULL, E_WARNING, "The second argument is not an array");
3314-
RETURN_FALSE;
3313+
zend_type_error("The second argument is not an array");
3314+
return;
33153315
}
33163316

33173317
/* shortcut for empty string */

ext/standard/tests/strings/strtr_variation8.phpt

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,15 @@ $replace_pairs_arr = array (
7575
// loop through with each element of the $replace_pairs array to test strtr() function
7676
$count = 1;
7777
for($index = 0; $index < count($replace_pairs_arr); $index++) {
78-
echo "\n-- Iteration $count --\n";
79-
$replace_pairs = $replace_pairs_arr[$index];
80-
var_dump( strtr($str, $replace_pairs) );
81-
$count ++;
78+
echo "\n-- Iteration $count --\n";
79+
$replace_pairs = $replace_pairs_arr[$index];
80+
try {
81+
var_dump( strtr($str, $replace_pairs) );
82+
} catch (\TypeError $e) {
83+
echo $e->getMessage() . "\n";
84+
}
85+
86+
$count ++;
8287
}
8388

8489
fclose($file_handle); //closing the file handle
@@ -89,34 +94,22 @@ echo "*** Done ***";
8994
*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***
9095

9196
-- Iteration 1 --
92-
93-
Warning: strtr(): The second argument is not an array in %s on line %d
94-
bool(false)
97+
The second argument is not an array
9598

9699
-- Iteration 2 --
97-
98-
Warning: strtr(): The second argument is not an array in %s on line %d
99-
bool(false)
100+
The second argument is not an array
100101

101102
-- Iteration 3 --
102-
103-
Warning: strtr(): The second argument is not an array in %s on line %d
104-
bool(false)
103+
The second argument is not an array
105104

106105
-- Iteration 4 --
107-
108-
Warning: strtr(): The second argument is not an array in %s on line %d
109-
bool(false)
106+
The second argument is not an array
110107

111108
-- Iteration 5 --
112-
113-
Warning: strtr(): The second argument is not an array in %s on line %d
114-
bool(false)
109+
The second argument is not an array
115110

116111
-- Iteration 6 --
117-
118-
Warning: strtr(): The second argument is not an array in %s on line %d
119-
bool(false)
112+
The second argument is not an array
120113

121114
-- Iteration 7 --
122115
string(6) "012atm"
@@ -128,52 +121,32 @@ string(6) "012atm"
128121
string(6) "122atm"
129122

130123
-- Iteration 10 --
131-
132-
Warning: strtr(): The second argument is not an array in %s on line %d
133-
bool(false)
124+
The second argument is not an array
134125

135126
-- Iteration 11 --
136-
137-
Warning: strtr(): The second argument is not an array in %s on line %d
138-
bool(false)
127+
The second argument is not an array
139128

140129
-- Iteration 12 --
141-
142-
Warning: strtr(): The second argument is not an array in %s on line %d
143-
bool(false)
130+
The second argument is not an array
144131

145132
-- Iteration 13 --
146-
147-
Warning: strtr(): The second argument is not an array in %s on line %d
148-
bool(false)
133+
The second argument is not an array
149134

150135
-- Iteration 14 --
151-
152-
Warning: strtr(): The second argument is not an array in %s on line %d
153-
bool(false)
136+
The second argument is not an array
154137

155138
-- Iteration 15 --
156-
157-
Warning: strtr(): The second argument is not an array in %s on line %d
158-
bool(false)
139+
The second argument is not an array
159140

160141
-- Iteration 16 --
161-
162-
Warning: strtr(): The second argument is not an array in %s on line %d
163-
bool(false)
142+
The second argument is not an array
164143

165144
-- Iteration 17 --
166-
167-
Warning: strtr(): The second argument is not an array in %s on line %d
168-
bool(false)
145+
The second argument is not an array
169146

170147
-- Iteration 18 --
171-
172-
Warning: strtr(): The second argument is not an array in %s on line %d
173-
bool(false)
148+
The second argument is not an array
174149

175150
-- Iteration 19 --
176-
177-
Warning: strtr(): The second argument is not an array in %s on line %d
178-
bool(false)
151+
The second argument is not an array
179152
*** Done ***

0 commit comments

Comments
 (0)