Skip to content

Commit d35faec

Browse files
authored
Split strtr zpp (#12583)
1 parent aa7465a commit d35faec

File tree

3 files changed

+27
-33
lines changed

3 files changed

+27
-33
lines changed

ext/standard/string.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,19 +3200,17 @@ PHP_FUNCTION(strtr)
32003200
char *to = NULL;
32013201
size_t to_len = 0;
32023202

3203-
ZEND_PARSE_PARAMETERS_START(2, 3)
3204-
Z_PARAM_STR(str)
3205-
Z_PARAM_ARRAY_HT_OR_STR(from_ht, from_str)
3206-
Z_PARAM_OPTIONAL
3207-
Z_PARAM_STRING_OR_NULL(to, to_len)
3208-
ZEND_PARSE_PARAMETERS_END();
3209-
3210-
if (!to && from_ht == NULL) {
3211-
zend_argument_type_error(2, "must be of type array, string given");
3212-
RETURN_THROWS();
3213-
} else if (to && from_str == NULL) {
3214-
zend_argument_type_error(2, "must be of type string, array given");
3215-
RETURN_THROWS();
3203+
if (ZEND_NUM_ARGS() <= 2) {
3204+
ZEND_PARSE_PARAMETERS_START(2, 2)
3205+
Z_PARAM_STR(str)
3206+
Z_PARAM_ARRAY_HT(from_ht)
3207+
ZEND_PARSE_PARAMETERS_END();
3208+
} else {
3209+
ZEND_PARSE_PARAMETERS_START(3, 3)
3210+
Z_PARAM_STR(str)
3211+
Z_PARAM_STR(from_str)
3212+
Z_PARAM_STRING(to, to_len)
3213+
ZEND_PARSE_PARAMETERS_END();
32163214
}
32173215

32183216
/* shortcut for empty string */

ext/standard/tests/strings/strtr_variation6.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,4 +113,4 @@ string(6) "012atm"
113113
-- Iteration 16 --
114114
string(6) "012ttm"
115115
-- Iteration 17 --
116-
strtr(): Argument #2 ($from) must be of type array|string, resource given
116+
strtr(): Argument #2 ($from) must be of type string, resource given

ext/standard/tests/strings/strtr_variation8.phpt

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -74,26 +74,26 @@ fclose($file_handle); //closing the file handle
7474

7575
echo "*** Done ***";
7676
?>
77-
--EXPECTF--
77+
--EXPECT--
7878
*** Testing strtr() function: with unexpected inputs for 'replace_pairs' ***
7979

8080
-- Iteration 1 --
81-
strtr(): Argument #2 ($from) must be of type array, string given
81+
strtr(): Argument #2 ($from) must be of type array, int given
8282

8383
-- Iteration 2 --
84-
strtr(): Argument #2 ($from) must be of type array, string given
84+
strtr(): Argument #2 ($from) must be of type array, int given
8585

8686
-- Iteration 3 --
87-
strtr(): Argument #2 ($from) must be of type array, string given
87+
strtr(): Argument #2 ($from) must be of type array, int given
8888

8989
-- Iteration 4 --
90-
strtr(): Argument #2 ($from) must be of type array, string given
90+
strtr(): Argument #2 ($from) must be of type array, float given
9191

9292
-- Iteration 5 --
93-
strtr(): Argument #2 ($from) must be of type array, string given
93+
strtr(): Argument #2 ($from) must be of type array, float given
9494

9595
-- Iteration 6 --
96-
strtr(): Argument #2 ($from) must be of type array, string given
96+
strtr(): Argument #2 ($from) must be of type array, float given
9797

9898
-- Iteration 7 --
9999
string(6) "012atm"
@@ -105,30 +105,26 @@ string(6) "012atm"
105105
string(6) "122atm"
106106

107107
-- Iteration 10 --
108-
strtr(): Argument #2 ($from) must be of type array, string given
108+
strtr(): Argument #2 ($from) must be of type array, true given
109109

110110
-- Iteration 11 --
111-
strtr(): Argument #2 ($from) must be of type array, string given
111+
strtr(): Argument #2 ($from) must be of type array, false given
112112

113113
-- Iteration 12 --
114-
strtr(): Argument #2 ($from) must be of type array, string given
114+
strtr(): Argument #2 ($from) must be of type array, true given
115115

116116
-- Iteration 13 --
117-
strtr(): Argument #2 ($from) must be of type array, string given
117+
strtr(): Argument #2 ($from) must be of type array, false given
118118

119119
-- Iteration 14 --
120-
121-
Deprecated: strtr(): Passing null to parameter #2 ($from) of type array|string is deprecated in %s on line %d
122-
strtr(): Argument #2 ($from) must be of type array, string given
120+
strtr(): Argument #2 ($from) must be of type array, null given
123121

124122
-- Iteration 15 --
125-
126-
Deprecated: strtr(): Passing null to parameter #2 ($from) of type array|string is deprecated in %s on line %d
127-
strtr(): Argument #2 ($from) must be of type array, string given
123+
strtr(): Argument #2 ($from) must be of type array, null given
128124

129125
-- Iteration 16 --
130-
strtr(): Argument #2 ($from) must be of type array, string given
126+
strtr(): Argument #2 ($from) must be of type array, sample given
131127

132128
-- Iteration 17 --
133-
strtr(): Argument #2 ($from) must be of type array|string, resource given
129+
strtr(): Argument #2 ($from) must be of type array, resource given
134130
*** Done ***

0 commit comments

Comments
 (0)