Skip to content

Commit e366cee

Browse files
committed
Deprecate mb_ereg_replace with non-string pattern
I'm counting this towards the non-string needle deprecation from https://wiki.php.net/rfc/deprecations_php_7_3. I wasn't aware that mb_ereg_replace() is also affected by this issue. It's even more ridiculous than usual here, because the integer is interpreted as an ASCII codepoint, even though these are supposed to be multibyte functions :(
1 parent 882dcb4 commit e366cee

File tree

4 files changed

+49
-2
lines changed

4 files changed

+49
-2
lines changed

UPGRADING

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ PHP 7.4 UPGRADE NOTES
139139
so is equivalent to calling a non-static method statically, which has been
140140
deprecated since PHP 7.0.
141141

142+
- Mbstring:
143+
. Passing a non-string pattern to mb_ereg_replace() is deprecated. Currently
144+
non-string patterns are interpreted as ASCII codepoints. In PHP 8 the
145+
pattern will be interpreted as a string instead.
146+
142147
========================================
143148
5. Changed Functions
144149
========================================

ext/mbstring/php_mbregex.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,10 @@ static void _php_mb_regex_ereg_replace_exec(INTERNAL_FUNCTION_PARAMETERS, OnigOp
10491049
arg_pattern = Z_STRVAL_P(arg_pattern_zval);
10501050
arg_pattern_len = Z_STRLEN_P(arg_pattern_zval);
10511051
} else {
1052+
php_error_docref(NULL, E_DEPRECATED,
1053+
"Non-string patterns will be interpreted as strings in the future. "
1054+
"Use an explicit chr() call to preserve the current behavior");
1055+
10521056
/* FIXME: this code is not multibyte aware! */
10531057
convert_to_long_ex(arg_pattern_zval);
10541058
pat_buf[0] = (char)Z_LVAL_P(arg_pattern_zval);

ext/mbstring/tests/bug72994.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var_dump($var1);
1414
--EXPECTF--
1515
Notice: Undefined variable: var in %s on line %d
1616

17+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
18+
1719
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %sbug72994.php on line %d
1820
bool(false)
1921
===DONE===

ext/mbstring/tests/mb_ereg_replace_variation1.phpt

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,52 +100,82 @@ echo "Done";
100100
*** Testing mb_ereg_replace() : usage variations ***
101101

102102
-- Iteration 1 --
103+
104+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
103105
string(10) "string_val"
104106

105107
-- Iteration 2 --
108+
109+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
106110
string(10) "string_val"
107111

108112
-- Iteration 3 --
113+
114+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
109115
string(10) "string_val"
110116

111117
-- Iteration 4 --
112118

113-
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %smb_ereg_replace_variation1.php on line %d
119+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
120+
121+
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %s on line %d
114122
bool(false)
115123

116124
-- Iteration 5 --
125+
126+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
117127
string(10) "string_val"
118128

119129
-- Iteration 6 --
120130

121-
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %smb_ereg_replace_variation1.php on line %d
131+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
132+
133+
Warning: mb_ereg_replace(): mbregex compile err: invalid code point value in %s on line %d
122134
bool(false)
123135

124136
-- Iteration 7 --
137+
138+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
125139
string(10) "string_val"
126140

127141
-- Iteration 8 --
142+
143+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
128144
string(10) "string_val"
129145

130146
-- Iteration 9 --
147+
148+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
131149
string(10) "string_val"
132150

133151
-- Iteration 10 --
152+
153+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
134154
string(10) "string_val"
135155

136156
-- Iteration 11 --
157+
158+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
137159
string(10) "string_val"
138160

139161
-- Iteration 12 --
162+
163+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
140164
string(10) "string_val"
141165

142166
-- Iteration 13 --
167+
168+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
143169
string(10) "string_val"
144170

145171
-- Iteration 14 --
172+
173+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
146174
string(10) "string_val"
147175

148176
-- Iteration 15 --
177+
178+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
149179
string(10) "string_val"
150180

151181
-- Iteration 16 --
@@ -164,11 +194,17 @@ string(10) "string_val"
164194
string(10) "string_val"
165195

166196
-- Iteration 21 --
197+
198+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
167199
string(10) "string_val"
168200

169201
-- Iteration 22 --
202+
203+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
170204
string(10) "string_val"
171205

172206
-- Iteration 23 --
207+
208+
Deprecated: mb_ereg_replace(): Non-string patterns will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior in %s on line %d
173209
string(10) "string_val"
174210
Done

0 commit comments

Comments
 (0)