Skip to content

Commit f4a9da3

Browse files
committed
Deprecate non-string needles in string search functions
Part of https://wiki.php.net/rfc/deprecations_php_7_3.
1 parent e6016ab commit f4a9da3

25 files changed

+542
-22
lines changed

ext/standard/string.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1881,6 +1881,10 @@ PHP_FUNCTION(stristr)
18811881
}
18821882
needle_char[1] = 0;
18831883

1884+
php_error_docref(NULL, E_DEPRECATED,
1885+
"Non-string needles will be interpreted as strings in the future. " \
1886+
"Use an explicit chr() call to preserve the current behavior");
1887+
18841888
found = php_stristr(haystack_dup, needle_char, ZSTR_LEN(haystack), 1);
18851889
}
18861890

@@ -1930,6 +1934,10 @@ PHP_FUNCTION(strstr)
19301934
}
19311935
needle_char[1] = 0;
19321936

1937+
php_error_docref(NULL, E_DEPRECATED,
1938+
"Non-string needles will be interpreted as strings in the future. " \
1939+
"Use an explicit chr() call to preserve the current behavior");
1940+
19331941
found = php_memnstr(ZSTR_VAL(haystack), needle_char, 1, ZSTR_VAL(haystack) + ZSTR_LEN(haystack));
19341942
}
19351943

@@ -1990,6 +1998,10 @@ PHP_FUNCTION(strpos)
19901998
}
19911999
needle_char[1] = 0;
19922000

2001+
php_error_docref(NULL, E_DEPRECATED,
2002+
"Non-string needles will be interpreted as strings in the future. " \
2003+
"Use an explicit chr() call to preserve the current behavior");
2004+
19932005
found = (char*)php_memnstr(ZSTR_VAL(haystack) + offset,
19942006
needle_char,
19952007
1,
@@ -2047,6 +2059,11 @@ PHP_FUNCTION(stripos)
20472059
if (php_needle_char(needle, needle_char) != SUCCESS) {
20482060
RETURN_FALSE;
20492061
}
2062+
2063+
php_error_docref(NULL, E_DEPRECATED,
2064+
"Non-string needles will be interpreted as strings in the future. " \
2065+
"Use an explicit chr() call to preserve the current behavior");
2066+
20502067
haystack_dup = php_string_tolower(haystack);
20512068
needle_char[0] = tolower(needle_char[0]);
20522069
needle_char[1] = '\0';
@@ -2095,6 +2112,11 @@ PHP_FUNCTION(strrpos)
20952112
if (php_needle_char(zneedle, ord_needle) != SUCCESS) {
20962113
RETURN_FALSE;
20972114
}
2115+
2116+
php_error_docref(NULL, E_DEPRECATED,
2117+
"Non-string needles will be interpreted as strings in the future. " \
2118+
"Use an explicit chr() call to preserve the current behavior");
2119+
20982120
ord_needle[1] = '\0';
20992121
needle = ord_needle;
21002122
needle_len = 1;
@@ -2159,6 +2181,11 @@ PHP_FUNCTION(strripos)
21592181
ZSTR_ALLOCA_FREE(ord_needle, use_heap);
21602182
RETURN_FALSE;
21612183
}
2184+
2185+
php_error_docref(NULL, E_DEPRECATED,
2186+
"Non-string needles will be interpreted as strings in the future. " \
2187+
"Use an explicit chr() call to preserve the current behavior");
2188+
21622189
ZSTR_VAL(ord_needle)[1] = '\0';
21632190
needle = ord_needle;
21642191
}
@@ -2263,6 +2290,10 @@ PHP_FUNCTION(strrchr)
22632290
RETURN_FALSE;
22642291
}
22652292

2293+
php_error_docref(NULL, E_DEPRECATED,
2294+
"Non-string needles will be interpreted as strings in the future. " \
2295+
"Use an explicit chr() call to preserve the current behavior");
2296+
22662297
found = zend_memrchr(ZSTR_VAL(haystack), needle_chr, ZSTR_LEN(haystack));
22672298
}
22682299

ext/standard/tests/strings/stripos.phpt

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ stripos() function test
2828

2929
echo "Done\n";
3030
?>
31-
--EXPECT--
31+
--EXPECTF--
3232
int(0)
3333
int(5)
3434
int(5)
@@ -45,11 +45,23 @@ int(0)
4545
bool(false)
4646
bool(false)
4747
bool(false)
48+
49+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
4850
bool(false)
51+
52+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
4953
bool(false)
54+
55+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
5056
bool(false)
57+
58+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
5159
bool(false)
60+
61+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
5262
bool(false)
63+
64+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
5365
bool(false)
5466
int(1)
5567
Done

ext/standard/tests/strings/stripos_variation1.phpt

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ for($index=0; $index<count($needle); $index++) {
8181
}
8282
echo "*** Done ***";
8383
?>
84-
--EXPECT--
84+
--EXPECTF--
8585
*** Testing stripos() function: with double quoted strings ***
8686
-- Iteration 1 --
8787
int(2)
@@ -117,16 +117,32 @@ int(9)
117117
int(8)
118118
bool(false)
119119
-- Iteration 12 --
120+
121+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
120122
int(8)
123+
124+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
121125
bool(false)
122126
-- Iteration 13 --
127+
128+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
123129
int(8)
130+
131+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
124132
bool(false)
125133
-- Iteration 14 --
134+
135+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
126136
int(8)
137+
138+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
127139
bool(false)
128140
-- Iteration 15 --
141+
142+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
129143
int(8)
144+
145+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
130146
bool(false)
131147
-- Iteration 16 --
132148
bool(false)

ext/standard/tests/strings/stripos_variation10.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,30 +95,48 @@ echo "*** Done ***";
9595
*** Testing stripos() function with unexpected values for needle ***
9696

9797
-- Iteration 1 --
98+
99+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
98100
bool(false)
99101

100102
-- Iteration 2 --
103+
104+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
101105
bool(false)
102106

103107
-- Iteration 3 --
108+
109+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
104110
bool(false)
105111

106112
-- Iteration 4 --
113+
114+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
107115
bool(false)
108116

109117
-- Iteration 5 --
118+
119+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
110120
bool(false)
111121

112122
-- Iteration 6 --
123+
124+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
113125
bool(false)
114126

115127
-- Iteration 7 --
128+
129+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
116130
bool(false)
117131

118132
-- Iteration 8 --
133+
134+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
119135
bool(false)
120136

121137
-- Iteration 9 --
138+
139+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
122140
bool(false)
123141

124142
-- Iteration 10 --
@@ -147,20 +165,30 @@ Warning: stripos(): needle is not a string or an integer in %s on line %d
147165
bool(false)
148166

149167
-- Iteration 15 --
168+
169+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
150170
bool(false)
151171

152172
-- Iteration 16 --
173+
174+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
153175
bool(false)
154176

155177
-- Iteration 17 --
178+
179+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
156180
bool(false)
157181

158182
-- Iteration 18 --
183+
184+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
159185
bool(false)
160186

161187
-- Iteration 19 --
162188

163189
Notice: Object of class sample could not be converted to int in %s on line %d
190+
191+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
164192
bool(false)
165193

166194
-- Iteration 20 --
@@ -170,9 +198,13 @@ bool(false)
170198
bool(false)
171199

172200
-- Iteration 22 --
201+
202+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
173203
bool(false)
174204

175205
-- Iteration 23 --
206+
207+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
176208
bool(false)
177209

178210
-- Iteration 24 --
@@ -181,8 +213,12 @@ Warning: stripos(): needle is not a string or an integer in %s on line %d
181213
%s
182214

183215
-- Iteration 25 --
216+
217+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
184218
bool(false)
185219

186220
-- Iteration 26 --
221+
222+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
187223
bool(false)
188224
*** Done ***

ext/standard/tests/strings/stripos_variation11.phpt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,31 +91,67 @@ echo "*** Done ***";
9191
--EXPECTF--
9292
*** Testing stripos() function with unexpected values for haystack and needle ***
9393
-- Iteration 1 --
94+
95+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
9496
bool(false)
97+
98+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
9599
bool(false)
96100
-- Iteration 2 --
101+
102+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
97103
bool(false)
104+
105+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
98106
bool(false)
99107
-- Iteration 3 --
108+
109+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
100110
bool(false)
111+
112+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
101113
bool(false)
102114
-- Iteration 4 --
115+
116+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
103117
bool(false)
118+
119+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
104120
bool(false)
105121
-- Iteration 5 --
122+
123+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
106124
bool(false)
125+
126+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
107127
bool(false)
108128
-- Iteration 6 --
129+
130+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
109131
bool(false)
132+
133+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
110134
bool(false)
111135
-- Iteration 7 --
136+
137+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
112138
bool(false)
139+
140+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
113141
bool(false)
114142
-- Iteration 8 --
143+
144+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
115145
bool(false)
146+
147+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
116148
bool(false)
117149
-- Iteration 9 --
150+
151+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
118152
bool(false)
153+
154+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
119155
bool(false)
120156
-- Iteration 10 --
121157

@@ -153,15 +189,23 @@ NULL
153189
Warning: stripos() expects parameter 1 to be string, array given in %s on line %d
154190
NULL
155191
-- Iteration 15 --
192+
193+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
156194
bool(false)
195+
196+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
157197
bool(false)
158198
-- Iteration 16 --
159199
bool(false)
160200

161201
Warning: stripos(): Offset not contained in string in %s on line %d
162202
bool(false)
163203
-- Iteration 17 --
204+
205+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
164206
bool(false)
207+
208+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
165209
bool(false)
166210
-- Iteration 18 --
167211
bool(false)
@@ -171,9 +215,13 @@ bool(false)
171215
-- Iteration 19 --
172216

173217
Notice: Object of class sample could not be converted to int in %s on line %d
218+
219+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
174220
bool(false)
175221

176222
Notice: Object of class sample could not be converted to int in %s on line %d
223+
224+
Deprecated: stripos(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
177225
bool(false)
178226
-- Iteration 20 --
179227
bool(false)

0 commit comments

Comments
 (0)