@@ -31,7 +31,8 @@ final class Ctype
31
31
*/
32
32
public static function ctype_alnum ($ text )
33
33
{
34
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
34
+ self ::checkType ($ text , __FUNCTION__ );
35
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
35
36
36
37
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^A-Za-z0-9]/ ' , $ text );
37
38
}
@@ -47,7 +48,8 @@ public static function ctype_alnum($text)
47
48
*/
48
49
public static function ctype_alpha ($ text )
49
50
{
50
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
51
+ self ::checkType ($ text , __FUNCTION__ );
52
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
51
53
52
54
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^A-Za-z]/ ' , $ text );
53
55
}
@@ -63,7 +65,8 @@ public static function ctype_alpha($text)
63
65
*/
64
66
public static function ctype_cntrl ($ text )
65
67
{
66
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
68
+ self ::checkType ($ text , __FUNCTION__ );
69
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
67
70
68
71
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^\x00-\x1f\x7f]/ ' , $ text );
69
72
}
@@ -79,7 +82,8 @@ public static function ctype_cntrl($text)
79
82
*/
80
83
public static function ctype_digit ($ text )
81
84
{
82
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
85
+ self ::checkType ($ text , __FUNCTION__ );
86
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
83
87
84
88
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^0-9]/ ' , $ text );
85
89
}
@@ -95,7 +99,8 @@ public static function ctype_digit($text)
95
99
*/
96
100
public static function ctype_graph ($ text )
97
101
{
98
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
102
+ self ::checkType ($ text , __FUNCTION__ );
103
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
99
104
100
105
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^!-~]/ ' , $ text );
101
106
}
@@ -111,7 +116,8 @@ public static function ctype_graph($text)
111
116
*/
112
117
public static function ctype_lower ($ text )
113
118
{
114
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
119
+ self ::checkType ($ text , __FUNCTION__ );
120
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
115
121
116
122
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^a-z]/ ' , $ text );
117
123
}
@@ -127,7 +133,8 @@ public static function ctype_lower($text)
127
133
*/
128
134
public static function ctype_print ($ text )
129
135
{
130
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
136
+ self ::checkType ($ text , __FUNCTION__ );
137
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
131
138
132
139
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^ -~]/ ' , $ text );
133
140
}
@@ -143,7 +150,8 @@ public static function ctype_print($text)
143
150
*/
144
151
public static function ctype_punct ($ text )
145
152
{
146
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
153
+ self ::checkType ($ text , __FUNCTION__ );
154
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
147
155
148
156
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^!-\/\:-@\[-`\{-~]/ ' , $ text );
149
157
}
@@ -159,7 +167,8 @@ public static function ctype_punct($text)
159
167
*/
160
168
public static function ctype_space ($ text )
161
169
{
162
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
170
+ self ::checkType ($ text , __FUNCTION__ );
171
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
163
172
164
173
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^\s]/ ' , $ text );
165
174
}
@@ -175,7 +184,8 @@ public static function ctype_space($text)
175
184
*/
176
185
public static function ctype_upper ($ text )
177
186
{
178
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
187
+ self ::checkType ($ text , __FUNCTION__ );
188
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
179
189
180
190
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^A-Z]/ ' , $ text );
181
191
}
@@ -191,7 +201,8 @@ public static function ctype_upper($text)
191
201
*/
192
202
public static function ctype_xdigit ($ text )
193
203
{
194
- $ text = self ::convert_int_to_char_for_ctype ($ text , __FUNCTION__ );
204
+ self ::checkType ($ text , __FUNCTION__ );
205
+ $ text = self ::convert_int_to_char_for_ctype ($ text );
195
206
196
207
return \is_string ($ text ) && '' !== $ text && !preg_match ('/[^A-Fa-f0-9]/ ' , $ text );
197
208
}
@@ -205,11 +216,10 @@ public static function ctype_xdigit($text)
205
216
* Any other integer is interpreted as a string containing the decimal digits of the integer.
206
217
*
207
218
* @param mixed $int
208
- * @param string $function
209
219
*
210
220
* @return mixed
211
221
*/
212
- private static function convert_int_to_char_for_ctype ($ int, $ function )
222
+ private static function convert_int_to_char_for_ctype ($ int )
213
223
{
214
224
if (!\is_int ($ int )) {
215
225
return $ int ;
@@ -219,14 +229,21 @@ private static function convert_int_to_char_for_ctype($int, $function)
219
229
return (string ) $ int ;
220
230
}
221
231
222
- if (\PHP_VERSION_ID >= 80100 ) {
223
- @trigger_error ($ function .'(): Argument of type int will be interpreted as string in the future ' , \E_USER_DEPRECATED );
224
- }
225
-
226
232
if ($ int < 0 ) {
227
233
$ int += 256 ;
228
234
}
229
235
230
236
return \chr ($ int );
231
237
}
238
+
239
+ /**
240
+ * @param mixed $input
241
+ * @param string $function
242
+ */
243
+ public static function checkType ($ input , $ function )
244
+ {
245
+ if (\PHP_VERSION_ID >= 80100 && !\is_string ($ input )) {
246
+ @trigger_error ($ function .'(): Argument of type ' .get_debug_type ($ input ).' will be interpreted as string in the future ' , \E_USER_DEPRECATED );
247
+ }
248
+ }
232
249
}
0 commit comments