1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Variable testing tests. |
4
|
|
|
* |
5
|
|
|
* @package PHPCheatsheets |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
// Prevent direct calls to this file. |
9
|
|
|
if ( ! defined( 'APP_DIR' ) ) { |
10
|
|
|
header( 'Status: 403 Forbidden' ); |
11
|
|
|
header( 'HTTP/1.1 403 Forbidden' ); |
12
|
|
|
exit(); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
require_once APP_DIR . '/class.vartype.php'; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Variable testing tests. |
20
|
|
|
*/ |
21
|
|
|
class VartypeTest extends Vartype { |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* The tests to run. |
25
|
|
|
* |
26
|
|
|
* @var array $tests Multi-dimensional array. |
27
|
|
|
* Possible lower level array keys: |
28
|
|
|
* - title Used as tab title |
29
|
|
|
* - tooltip Additional code sample for tooltip on tab |
30
|
|
|
* - url Relevant PHP Manual page |
31
|
|
|
* - arg Function arguments |
32
|
|
|
* - function Function to run |
33
|
|
|
* - Notes Array of notes on this test |
34
|
|
|
*/ |
35
|
|
|
var $tests = array( |
36
|
|
|
'gettype' => array( |
37
|
|
|
'title' => 'gettype()', |
38
|
|
|
'url' => 'https://php.net/gettype', |
39
|
|
|
'arg' => '$x', |
40
|
|
|
'function' => 'pr_str( gettype( $x ) );', |
41
|
|
|
), |
42
|
|
|
|
43
|
|
|
'isset' => array( |
44
|
|
|
'title' => 'isset()', |
45
|
|
|
'url' => 'https://php.net/isset', |
46
|
|
|
'arg' => '$x', |
47
|
|
|
'function' => 'pr_bool( isset( $x ) );', |
48
|
|
|
), |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
// Will be removed from $tests property from constructor if not on PHP 7+ to prevent parse errors. |
52
|
|
|
'null_coalesce' => array( |
53
|
|
|
'title' => '$x ?? \'not-set\'', |
54
|
|
|
'url' => 'https://php.net/language.operators.comparison', |
55
|
|
|
'arg' => '$x', |
56
|
|
|
'function' => 'pr_var( $x ?? \'not-set\' );', |
57
|
|
|
'notes' => array( |
58
|
|
|
'<p>The Null Coalesce operator is only available in PHP 7.0.0+.</p>', |
59
|
|
|
), |
60
|
|
|
), |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
|
64
|
|
|
'var' => array( |
65
|
|
|
'title' => '$x', |
66
|
|
|
'arg' => '$x', |
67
|
|
|
'function' => 'pr_bool( $x );', |
68
|
|
|
), |
69
|
|
|
'not_var' => array( |
70
|
|
|
'title' => '!$x', |
71
|
|
|
'arg' => '$x', |
72
|
|
|
'function' => 'pr_bool( ! $x );', |
73
|
|
|
), |
74
|
|
|
'if_var' => array( |
75
|
|
|
'title' => 'if( $x ) {..}', |
76
|
|
|
'arg' => '$x', |
77
|
|
|
'function' => 'if ( $x ) { pr_bool( true ); } else { pr_bool( false ); }', |
78
|
|
|
), |
79
|
|
|
'if_not_var' => array( |
80
|
|
|
'title' => 'if( ! $x ) {..}', |
81
|
|
|
'arg' => '$x', |
82
|
|
|
'function' => 'if ( ! $x ) { pr_bool( true ); } else { pr_bool( false ); }', |
83
|
|
|
), |
84
|
|
|
|
85
|
|
|
|
86
|
|
|
/* |
87
|
|
|
* Test is_...() functions |
88
|
|
|
*/ |
89
|
|
|
'is_array' => array( |
90
|
|
|
'title' => 'is_array()', |
91
|
|
|
'url' => 'https://php.net/is_array', |
92
|
|
|
'arg' => '$x', |
93
|
|
|
'function' => 'pr_bool( is_array( $x ) );', |
94
|
|
|
), |
95
|
|
|
'is_binary' => array( |
96
|
|
|
'title' => 'is_binary()', |
97
|
|
|
'url' => 'https://php.net/is_binary', |
98
|
|
|
'arg' => '$x', |
99
|
|
|
'function' => 'if ( function_exists( \'is_binary\' ) ) { pr_bool( is_binary( $x ) ); } else { print "E: not available (PHP 6.0.0+)\n"; }', |
100
|
|
|
), |
101
|
|
|
'is_bool' => array( |
102
|
|
|
'title' => 'is_bool()', |
103
|
|
|
'url' => 'https://php.net/is_bool', |
104
|
|
|
'arg' => '$x', |
105
|
|
|
'function' => 'pr_bool( is_bool( $x ) );', |
106
|
|
|
), |
107
|
|
|
'is_callable' => array( |
108
|
|
|
'title' => 'is_callable()', |
109
|
|
|
'url' => 'https://php.net/is_callable', |
110
|
|
|
'arg' => '$x', |
111
|
|
|
'function' => 'if ( function_exists( \'is_callable\' ) ) { pr_bool( is_callable( $x ) ); } else { print "E: not available (PHP 4.0.6+)\n"; }', |
112
|
|
|
), |
113
|
|
|
'is_float' => array( |
114
|
|
|
'title' => 'is_float()', |
115
|
|
|
'url' => 'https://php.net/is_float', |
116
|
|
|
'arg' => '$x', |
117
|
|
|
'function' => 'pr_bool( is_float( $x ) );', |
118
|
|
|
), |
119
|
|
|
'is_int' => array( |
120
|
|
|
'title' => 'is_int()', |
121
|
|
|
'url' => 'https://php.net/is_int', |
122
|
|
|
'arg' => '$x', |
123
|
|
|
'function' => 'pr_bool( is_int( $x ) );', |
124
|
|
|
), |
125
|
|
|
'is_null' => array( |
126
|
|
|
'title' => 'is_null()', |
127
|
|
|
'url' => 'https://php.net/is_null', |
128
|
|
|
'arg' => '$x', |
129
|
|
|
'function' => 'if ( function_exists( \'is_null\' ) ) { pr_bool( is_null( $x ) ); } else { print "E: not available (PHP 4.0.4+)\n"; }', |
130
|
|
|
), |
131
|
|
|
'is_numeric' => array( |
132
|
|
|
'title' => 'is_numeric()', |
133
|
|
|
'url' => 'https://php.net/is_numeric', |
134
|
|
|
'arg' => '$x', |
135
|
|
|
'function' => 'pr_bool( is_numeric( $x ) );', |
136
|
|
|
), |
137
|
|
|
'is_object' => array( |
138
|
|
|
'title' => 'is_object()', |
139
|
|
|
'url' => 'https://php.net/is_object', |
140
|
|
|
'arg' => '$x', |
141
|
|
|
'function' => 'pr_bool( is_object( $x ) );', |
142
|
|
|
), |
143
|
|
|
'is_resource' => array( |
144
|
|
|
'title' => 'is_resource()', |
145
|
|
|
'url' => 'https://php.net/is_resource', |
146
|
|
|
'arg' => '$x', |
147
|
|
|
'function' => 'pr_bool( is_resource( $x ) );', |
148
|
|
|
), |
149
|
|
|
'is_scalar' => array( |
150
|
|
|
'title' => 'is_scalar()', |
151
|
|
|
'url' => 'https://php.net/is_scalar', |
152
|
|
|
'arg' => '$x', |
153
|
|
|
'function' => 'if ( function_exists( \'is_scalar\' ) ) { pr_bool( is_scalar( $x ) ); } else { print "E: not available (PHP 4.0.5+)\n"; }', |
154
|
|
|
), |
155
|
|
|
'is_string' => array( |
156
|
|
|
'title' => 'is_string()', |
157
|
|
|
'url' => 'https://php.net/is_string', |
158
|
|
|
'arg' => '$x', |
159
|
|
|
'function' => 'pr_bool( is_string( $x ) );', |
160
|
|
|
), |
161
|
|
|
|
162
|
|
|
|
163
|
|
|
// Float specific. |
164
|
|
|
'is_nan' => array( |
165
|
|
|
'title' => 'is_nan()', |
166
|
|
|
'url' => 'https://php.net/is_nan', |
167
|
|
|
'arg' => '$x', |
168
|
|
|
'function' => 'if ( function_exists( \'is_nan\' ) ) { $r = is_nan( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 4.2.0+)\n"; }', |
169
|
|
|
), |
170
|
|
|
'is_finite' => array( |
171
|
|
|
'title' => 'is_finite()', |
172
|
|
|
'url' => 'https://php.net/is_finite', |
173
|
|
|
'arg' => '$x', |
174
|
|
|
'function' => 'if ( function_exists( \'is_finite\' ) ) { $r = is_finite( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 4.2.0+)\n"; }', |
175
|
|
|
), |
176
|
|
|
'is_infinite' => array( |
177
|
|
|
'title' => 'is_infinite()', |
178
|
|
|
'url' => 'https://php.net/is_infinite', |
179
|
|
|
'arg' => '$x', |
180
|
|
|
'function' => 'if ( function_exists( \'is_infinite\' ) ) { $r = is_infinite( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 4.2.0+)\n"; }', |
181
|
|
|
), |
182
|
|
|
|
183
|
|
|
|
184
|
|
|
// Array related. |
185
|
|
|
'is_iterable' => array( |
186
|
|
|
'title' => 'is_iterable()', |
187
|
|
|
'url' => 'https://php.net/is_iterable', |
188
|
|
|
'arg' => '$x', |
189
|
|
|
'function' => 'if ( function_exists( \'is_iterable\' ) ) { pr_bool( is_iterable( $x ) ); } else { print "E: not available (PHP 7.1.0+)\n"; }', |
190
|
|
|
), |
191
|
|
|
'is_countable' => array( |
192
|
|
|
'title' => 'is_countable()', |
193
|
|
|
'url' => 'https://php.net/is_countable', |
194
|
|
|
'arg' => '$x', |
195
|
|
|
'function' => 'if ( function_exists( \'is_countable\' ) ) { pr_bool( is_countable( $x ) ); } else { print "E: not available (PHP 7.3.0+)\n"; }', |
196
|
|
|
), |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
/* |
200
|
|
|
* Type casting. |
201
|
|
|
*/ |
202
|
|
|
'array' => array( |
203
|
|
|
'title' => '(array)', |
204
|
|
|
'url' => 'https://php.net/language.types.array#language.types.array.casting', |
205
|
|
|
'arg' => '$x', |
206
|
|
|
'function' => 'pr_var( (array) $x, \'\', true, true );', |
207
|
|
|
), |
208
|
|
|
'bool' => array( |
209
|
|
|
'title' => '(bool)', |
210
|
|
|
'url' => 'https://php.net/language.types.boolean#language.types.boolean.casting', |
211
|
|
|
'arg' => '$x', |
212
|
|
|
'function' => 'pr_bool( (bool) $x );', |
213
|
|
|
), |
214
|
|
|
'float' => array( |
215
|
|
|
'title' => '(float)', |
216
|
|
|
'url' => 'https://php.net/language.types.float#language.types.float.casting', |
217
|
|
|
'arg' => '$x', |
218
|
|
|
'function' => 'pr_flt( (float) $x );', |
219
|
|
|
), |
220
|
|
|
'int' => array( |
221
|
|
|
'title' => '(int)', |
222
|
|
|
'url' => 'https://php.net/language.types.integer#language.types.integer.casting', |
223
|
|
|
'arg' => '$x', |
224
|
|
|
'function' => '$r = (int) $x; if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); }', |
225
|
|
|
), |
226
|
|
|
'object' => array( |
227
|
|
|
'title' => '(object)', |
228
|
|
|
'url' => 'https://php.net/language.types.object#language.types.object.casting', |
229
|
|
|
'arg' => '$x', |
230
|
|
|
'function' => 'pr_var( (object) $x, \'\', true, true );', |
231
|
|
|
), |
232
|
|
|
'string' => array( |
233
|
|
|
'title' => '(string)', |
234
|
|
|
'url' => 'https://php.net/language.types.string#language.types.string.casting', |
235
|
|
|
'arg' => '$x', |
236
|
|
|
'function' => 'pr_str( (string) $x );', |
237
|
|
|
), |
238
|
|
|
'unset' => array( |
239
|
|
|
'title' => '(unset)', |
240
|
|
|
'url' => 'https://php.net/language.types.null#language.types.null.casting', |
241
|
|
|
'arg' => '$x', |
242
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50000 ) { pr_var( (unset) $x, \'\', true, true ); } else { print "E: not available (PHP 5+)\n"; }', |
243
|
|
|
), |
244
|
|
|
'f_unset' => array( |
245
|
|
|
'title' => 'unset()', |
246
|
|
|
'url' => 'https://php.net/unset', |
247
|
|
|
'arg' => '$x', |
248
|
|
|
'function' => 'unset( $x ); pr_var( $x, \'\', true, true );', |
249
|
|
|
), |
250
|
|
|
|
251
|
|
|
|
252
|
|
|
/* |
253
|
|
|
* ...val() |
254
|
|
|
*/ |
255
|
|
|
'floatval' => array( |
256
|
|
|
'title' => 'floatval()', |
257
|
|
|
'url' => 'https://php.net/floatval', |
258
|
|
|
'arg' => '$x', |
259
|
|
|
'function' => '$r = floatval( $x ); if ( is_float( $r ) ) { pr_flt( $r ); } else if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); }', |
260
|
|
|
), |
261
|
|
|
'intval' => array( |
262
|
|
|
'title' => 'intval()', |
263
|
|
|
'url' => 'https://php.net/intval', |
264
|
|
|
'arg' => '$x', |
265
|
|
|
'function' => '$r = intval( $x ); if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); }', |
266
|
|
|
), |
267
|
|
|
'strval' => array( |
268
|
|
|
'title' => 'strval()', |
269
|
|
|
'url' => 'https://php.net/strval', |
270
|
|
|
'arg' => '$x', |
271
|
|
|
'function' => '$r = strval( $x ); if ( is_string( $r ) ) { pr_str( $r ); } else { pr_var( $r, \'\', true, true ); }', |
272
|
|
|
), |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
/* |
276
|
|
|
* Loose type juggling. |
277
|
|
|
*/ |
278
|
|
|
'juggle_int' => array( |
279
|
|
|
'title' => '$x + 0', |
280
|
|
|
'url' => 'https://php.net/language.types.type-juggling', |
281
|
|
|
'arg' => '$x', |
282
|
|
|
'function' => ' |
283
|
|
|
if ( ! is_array( $x ) && ( PHP_VERSION_ID > 50005 || ! is_object( $x ) ) ) { |
284
|
|
|
$x = $x + 0; |
285
|
|
|
if ( is_int( $x ) ) { |
286
|
|
|
pr_int( $x ); |
287
|
|
|
} |
288
|
|
|
else if ( is_float( $x ) ) { |
289
|
|
|
pr_flt( $x ); |
290
|
|
|
} |
291
|
|
|
else { |
292
|
|
|
pr_var( $x, \'\', true, true ); |
293
|
|
|
} |
294
|
|
|
} |
295
|
|
|
else { |
296
|
|
|
trigger_error( \'Unsupported operand types\', E_USER_ERROR ); |
297
|
|
|
} |
298
|
|
|
', // Note: has PHP5 equivalent in class.vartype-php5.php. |
299
|
|
|
), |
300
|
|
|
'juggle_flt' => array( |
301
|
|
|
'title' => '$x + 0.0', |
302
|
|
|
'url' => 'https://php.net/language.types.type-juggling', |
303
|
|
|
'arg' => '$x', |
304
|
|
|
'function' => ' |
305
|
|
|
if ( ! is_array( $x ) && ( PHP_VERSION_ID > 50005 || ! is_object( $x ) ) ) { |
306
|
|
|
$r = $x + 0.0; |
307
|
|
|
if ( is_float( $r ) ) { |
308
|
|
|
pr_flt( $r ); |
309
|
|
|
} |
310
|
|
|
else if ( is_int( $r ) ) { |
311
|
|
|
pr_int( $r ); |
312
|
|
|
} |
313
|
|
|
else { |
314
|
|
|
pr_var( $r, \'\', true, true ); |
315
|
|
|
} |
316
|
|
|
} |
317
|
|
|
else { |
318
|
|
|
trigger_error( \'Unsupported operand types\', E_USER_ERROR ); |
319
|
|
|
} |
320
|
|
|
', // Note: has PHP5 equivalent in class.vartype-php5.php. |
321
|
|
|
), |
322
|
|
|
'juggle_str' => array( |
323
|
|
|
'title' => '$x . \'\'', |
324
|
|
|
'url' => 'https://php.net/language.types.type-juggling', |
325
|
|
|
'arg' => '$x', |
326
|
|
|
'function' => 'pr_str( $x . \' \' );', |
327
|
|
|
), |
328
|
|
|
|
329
|
|
|
|
330
|
|
|
/* |
331
|
|
|
* Test settype() |
332
|
|
|
*/ |
333
|
|
|
'settype_array' => array( |
334
|
|
|
'title' => 'settype ( $copy, \'array\' )', |
335
|
|
|
'url' => 'https://php.net/settype', |
336
|
|
|
'arg' => '$x', |
337
|
|
|
'function' => '$pass = settype( $x, \'array\' ); if ( $pass === true ) { pr_var( $x, \'\', true, true ); } else { print \'FAILED\'; }', |
338
|
|
|
), |
339
|
|
|
'settype_bool' => array( |
340
|
|
|
'title' => 'settype ( $copy, \'bool\' )', |
341
|
|
|
'url' => 'https://php.net/settype', |
342
|
|
|
'arg' => '$x', |
343
|
|
|
'function' => '$pass = settype( $x, \'boolean\' ); if ( $pass === true ) { pr_bool( $x ); } else { print \'FAILED\'; }', |
344
|
|
|
), |
345
|
|
|
'settype_float' => array( |
346
|
|
|
'title' => 'settype ( $copy, \'float\' )', |
347
|
|
|
'url' => 'https://php.net/settype', |
348
|
|
|
'arg' => '$x', |
349
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 40200 ) { $pass = settype( $x, \'float\' ); } else { $pass = settype( $x, \'double\' ); } if ( $pass === true ) { pr_flt( $x ); } else { print \'FAILED\'; }', |
350
|
|
|
), |
351
|
|
|
'settype_int' => array( |
352
|
|
|
'title' => 'settype ( $copy, \'int\' )', |
353
|
|
|
'url' => 'https://php.net/settype', |
354
|
|
|
'arg' => '$x', |
355
|
|
|
'function' => '$pass = settype( $x, \'integer\' ); if ( $pass === true ) { if ( is_int( $x ) ) { pr_int( $x ); } else { pr_var( $x, \'\', true, true ); } } else { print \'FAILED\'; }', |
356
|
|
|
), |
357
|
|
|
'settype_null' => array( |
358
|
|
|
'title' => 'settype ( $copy, \'null\' )', |
359
|
|
|
'url' => 'https://php.net/settype', |
360
|
|
|
'arg' => '$x', |
361
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 40200 ) { $pass = settype( $x, \'null\' ); if ( $pass === true ) { pr_var( $x, \'\', true, true ); } else { print \'FAILED\'; } } else { print "E: not available (PHP 4.2.0+)\n"; }', |
362
|
|
|
), |
363
|
|
|
'settype_object' => array( |
364
|
|
|
'title' => 'settype ( $copy, \'object\' )', |
365
|
|
|
'url' => 'https://php.net/settype', |
366
|
|
|
'arg' => '$x', |
367
|
|
|
'function' => '$pass = settype( $x, \'object\' ); if ( $pass === true ) { pr_var( $x, \'\', true, true ); } else { print \'FAILED\'; }', |
368
|
|
|
), |
369
|
|
|
'settype_string' => array( |
370
|
|
|
'title' => 'settype ( $copy, \'string\' )', |
371
|
|
|
'url' => 'https://php.net/settype', |
372
|
|
|
'arg' => '$x', |
373
|
|
|
'function' => '$pass = settype( $x, \'string\' ); if ( $pass === true ) { pr_str( $x ); } else { print \'FAILED\'; }', |
374
|
|
|
'notes' => array( |
375
|
|
|
'<p>Depending on your error handling settings/exception catching and your PHP version, using <code>settype( $copy, \'string\' )</code> on an object which does not have a <code>__toString()</code> method will result either in the string <code>Object</code> or will return a (catchable) fatal error.</p>', |
376
|
|
|
'<p>Before PHP < 5.2.0, the <code>__toString()</code> method was only available to echo/print statements, so casting to string would still result in <code>Object</code>, even when the object contained a <code>__toString()</code> method.</p>', |
377
|
|
|
), |
378
|
|
|
), |
379
|
|
|
|
380
|
|
|
|
381
|
|
|
/* |
382
|
|
|
* Tests using CastToType class. |
383
|
|
|
* |
384
|
|
|
* @see https://github.com/jrfnl/PHP-cast-to-type.git |
385
|
|
|
*/ |
386
|
|
|
'cast_to_type_array' => array( |
387
|
|
|
'title' => 'CastToType::_array ( $x )', |
388
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
389
|
|
|
'arg' => '$x', |
390
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ); pr_var( CastToType::_array( $x ), \'\', true, true ); } else { print \' \'; }', |
391
|
|
|
'notes' => array( |
392
|
|
|
'<p>Uses an external library</p>', |
393
|
|
|
), |
394
|
|
|
), |
395
|
|
|
'cast_to_type_bool' => array( |
396
|
|
|
'title' => 'CastToType::_bool ( $x )', |
397
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
398
|
|
|
'arg' => '$x', |
399
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_bool( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
400
|
|
|
'notes' => array( |
401
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
402
|
|
|
), |
403
|
|
|
), |
404
|
|
|
'cast_to_type_float' => array( |
405
|
|
|
'title' => 'CastToType::_float ( $x )', |
406
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
407
|
|
|
'arg' => '$x', |
408
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_float( $x ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
409
|
|
|
'notes' => array( |
410
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
411
|
|
|
), |
412
|
|
|
), |
413
|
|
|
'cast_to_type_int' => array( |
414
|
|
|
'title' => 'CastToType::_int ( $x )', |
415
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
416
|
|
|
'arg' => '$x', |
417
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_int( $x ); if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
418
|
|
|
'notes' => array( |
419
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
420
|
|
|
), |
421
|
|
|
), |
422
|
|
|
'cast_to_type_null' => array( |
423
|
|
|
'title' => 'CastToType::_null ( $x )', |
424
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
425
|
|
|
'arg' => '$x', |
426
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; pr_var( CastToType::_null( $x ), \'\', true, true ); } else { print \' \'; }', |
427
|
|
|
'notes' => array( |
428
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
429
|
|
|
), |
430
|
|
|
), |
431
|
|
|
'cast_to_type_object' => array( |
432
|
|
|
'title' => 'CastToType::_object ( $x )', |
433
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
434
|
|
|
'arg' => '$x', |
435
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; pr_var( CastToType::_object( $x ), \'\', true, true ); } else { print \' \'; }', |
436
|
|
|
'notes' => array( |
437
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
438
|
|
|
), |
439
|
|
|
), |
440
|
|
|
'cast_to_type_string' => array( |
441
|
|
|
'title' => 'CastToType::_string ( $x )', |
442
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
443
|
|
|
'arg' => '$x', |
444
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_string( $x ); if ( is_string( $r ) ) { pr_str( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
445
|
|
|
'notes' => array( |
446
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
447
|
|
|
), |
448
|
|
|
), |
449
|
|
|
|
450
|
|
|
|
451
|
|
|
'cast_to_type_array_not_empty' => array( |
452
|
|
|
'title' => 'CastToType::_array ( $x, false )', |
453
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
454
|
|
|
'arg' => '$x', |
455
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; pr_var( CastToType::_array( $x, false ), \'\', true, true ); } else { print \' \'; }', |
456
|
|
|
'notes' => array( |
457
|
|
|
'<p>Uses an external library</p>', |
458
|
|
|
), |
459
|
|
|
), |
460
|
|
|
'cast_to_type_bool_not_empty_recurse_arrays' => array( |
461
|
|
|
'title' => 'CastToType::_bool ( $x, false, false )', |
462
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
463
|
|
|
'arg' => '$x', |
464
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_bool( $x, false, false ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
465
|
|
|
'notes' => array( |
466
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
467
|
|
|
), |
468
|
|
|
), |
469
|
|
|
'cast_to_type_float_not_empty_recurse_arrays' => array( |
470
|
|
|
'title' => 'CastToType::_float ( $x, false, false )', |
471
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
472
|
|
|
'arg' => '$x', |
473
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_float( $x, false, false ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
474
|
|
|
'notes' => array( |
475
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
476
|
|
|
), |
477
|
|
|
), |
478
|
|
|
'cast_to_type_int_not_empty_recurse_arrays' => array( |
479
|
|
|
'title' => 'CastToType::_int ( $x, false, false )', |
480
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
481
|
|
|
'arg' => '$x', |
482
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_int( $x, false, false ); if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
483
|
|
|
'notes' => array( |
484
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
485
|
|
|
), |
486
|
|
|
), |
487
|
|
|
'cast_to_type_object_not_empty' => array( |
488
|
|
|
'title' => 'CastToType::_object ( $x, false )', |
489
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
490
|
|
|
'arg' => '$x', |
491
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; pr_var( CastToType::_object( $x, false ), \'\', true, true ); } else { print \' \'; }', |
492
|
|
|
'notes' => array( |
493
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
494
|
|
|
), |
495
|
|
|
), |
496
|
|
|
'cast_to_type_string_not_empty_recurse_arrays' => array( |
497
|
|
|
'title' => 'CastToType::_string ( $x, false, false )', |
498
|
|
|
'url' => 'https://github.com/jrfnl/PHP-cast-to-type.git', |
499
|
|
|
'arg' => '$x', |
500
|
|
|
'function' => 'if ( file_exists( APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\' ) ) { include_once APP_DIR . \'/include/PHP-cast-to-type/cast-to-type.php\'; $r = CastToType::_string( $x, false, false ); if ( is_string( $r ) ) { pr_str( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \' \'; }', |
501
|
|
|
'notes' => array( |
502
|
|
|
'<p>Uses an <a href="https://github.com/jrfnl/PHP-cast-to-type.git" target="_blank">external library</a></p>', |
503
|
|
|
), |
504
|
|
|
), |
505
|
|
|
|
506
|
|
|
|
507
|
|
|
|
508
|
|
|
/* |
509
|
|
|
* Absolute numbers |
510
|
|
|
*/ |
511
|
|
|
'abs' => array( |
512
|
|
|
'title' => 'abs()', |
513
|
|
|
'url' => 'https://php.net/abs', |
514
|
|
|
'arg' => '$x', |
515
|
|
|
'function' => '$r = abs( $x ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
516
|
|
|
), |
517
|
|
|
|
518
|
|
|
|
519
|
|
|
/* |
520
|
|
|
* Some rounding functions |
521
|
|
|
*/ |
522
|
|
|
'floor' => array( |
523
|
|
|
'title' => 'floor()', |
524
|
|
|
'url' => 'https://php.net/floor', |
525
|
|
|
'arg' => '$x', |
526
|
|
|
'function' => '$r = floor( $x ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
527
|
|
|
), |
528
|
|
|
'ceil' => array( |
529
|
|
|
'title' => 'ceil()', |
530
|
|
|
'url' => 'https://php.net/ceil', |
531
|
|
|
'arg' => '$x', |
532
|
|
|
'function' => '$r = ceil( $x ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
533
|
|
|
), |
534
|
|
|
'round' => array( |
535
|
|
|
'title' => 'round()', |
536
|
|
|
'url' => 'https://php.net/round', |
537
|
|
|
'arg' => '$x', |
538
|
|
|
'function' => '$r = round( $x ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
539
|
|
|
), |
540
|
|
|
|
541
|
|
|
|
542
|
|
|
|
543
|
|
|
|
544
|
|
|
/* |
545
|
|
|
* Some string related functions |
546
|
|
|
*/ |
547
|
|
|
'empty' => array( |
548
|
|
|
'title' => 'empty()', |
549
|
|
|
'url' => 'https://php.net/empty', |
550
|
|
|
'arg' => '$x', |
551
|
|
|
'function' => 'pr_bool( empty( $x ) );', |
552
|
|
|
), |
553
|
|
|
'strlen' => array( |
554
|
|
|
'title' => 'strlen()', |
555
|
|
|
'url' => 'https://php.net/strlen', |
556
|
|
|
'arg' => '$x', |
557
|
|
|
'function' => '$r = strlen( $x ); if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); }', |
558
|
|
|
), |
559
|
|
|
'count_chars' => array( |
560
|
|
|
'title' => 'count_chars (…)', |
561
|
|
|
'tooltip' => 'array_sum( count_chars( $x, 1 ) )', |
562
|
|
|
'url' => 'https://php.net/count_chars', |
563
|
|
|
'arg' => '$x', |
564
|
|
|
'function' => 'pr_var( array_sum( count_chars( $x, 1 ) ), \'\', true, true );', |
565
|
|
|
), |
566
|
|
|
'str_shuffle' => array( |
567
|
|
|
'title' => 'str_shuffle ( $x )', |
568
|
|
|
'url' => 'https://php.net/str_shuffle', |
569
|
|
|
'arg' => '$x', |
570
|
|
|
'function' => 'pr_var( str_shuffle( $x ), \'\', true, true );', |
571
|
|
|
), |
572
|
|
|
|
573
|
|
|
'mb_strlen' => array( |
574
|
|
|
'title' => 'mb_strlen()', |
575
|
|
|
'url' => 'https://php.net/mb-strlen', |
576
|
|
|
'arg' => '$x', |
577
|
|
|
'function' => 'if ( function_exists( \'mb_strlen\' ) ) { $r = mb_strlen( $x, \'UTF-8\' ); if ( is_int( $r ) ) { pr_int( $r ); } else if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print \'E: mbstring extension not installed\'; }', |
578
|
|
|
), |
579
|
|
|
'trim' => array( |
580
|
|
|
'title' => 'trim()', |
581
|
|
|
'url' => 'https://php.net/trim', |
582
|
|
|
'arg' => '$x', |
583
|
|
|
'function' => 'pr_var( trim( $x ), \'\', true, true );', |
584
|
|
|
), |
585
|
|
|
'char_access' => array( |
586
|
|
|
'title' => '$x{2}', |
587
|
|
|
'tooltip' => 'String character access by index.', |
588
|
|
|
'url' => 'https://php.net/manual/en/language.types.string.php#language.types.string.substr', |
589
|
|
|
'arg' => '$x', |
590
|
|
|
'function' => 'if ( ! is_object( $x ) ) { pr_var( $x{2}, \'\', true, true ); } else { $class = get_class( $x ); trigger_error( \'Cannot use object of type \' . $class . \' as array\', E_USER_ERROR ); unset( $class ); }', |
591
|
|
|
), |
592
|
|
|
|
593
|
|
|
|
594
|
|
|
|
595
|
|
|
/* |
596
|
|
|
* Some array related functions |
597
|
|
|
*/ |
598
|
|
|
'count' => array( |
599
|
|
|
'title' => 'count()', |
600
|
|
|
'url' => 'https://php.net/count', |
601
|
|
|
'arg' => '$x', |
602
|
|
|
'function' => 'pr_int( count( $x ) );', |
603
|
|
|
), |
604
|
|
|
'count_mt_0' => array( |
605
|
|
|
'title' => 'count() > 0', |
606
|
|
|
'url' => 'https://php.net/count', |
607
|
|
|
'arg' => '$x', |
608
|
|
|
'function' => 'pr_bool( ( count( $x ) > 0 ) );', |
609
|
|
|
), |
610
|
|
|
'isset_0' => array( |
611
|
|
|
'title' => 'isset ( $x[0] )', |
612
|
|
|
'url' => 'https://php.net/isset', |
613
|
|
|
'arg' => '$x', |
614
|
|
|
'function' => 'if ( ! is_object( $x ) ) { pr_bool( isset( $x[0] ) ); } else { $class = get_class( $x ); trigger_error( \'Cannot use object of type \' . $class . \' as array\', E_USER_ERROR ); unset( $class ); }', |
615
|
|
|
'notes' => array( |
616
|
|
|
'<p> |
617
|
|
|
Whether to use <code>isset()</code> or <code>array_key_exists()</code> depends on what you want to know: |
618
|
|
|
</p> |
619
|
|
|
<ul> |
620
|
|
|
<li><code>isset( $array[$key] )</code> will tell you whether the array key exists <strong>and</strong> has been assigned a value.<br /> |
621
|
|
|
Used on its own it will give undesired results when used on strings as characters within a string can be approached using the <code>$x[]</code> syntax as well.<br /> |
622
|
|
|
Also, it will cause fatal errors when used on objects.</li> |
623
|
|
|
<li><code>array_key_exists( $key, $array )</code> will tell you only whether the array key exists, but will not check whether it has a value assigned to it.<br /> |
624
|
|
|
Used on its own, it will show a warning if $array is not an array</li> |
625
|
|
|
</ul> |
626
|
|
|
<p> |
627
|
|
|
This said, we can conclude that to avoid warnings and undesired results you will always have to use an <code>is_array()</code> first.<br /> |
628
|
|
|
Also note that <code>isset()</code> is faster than <code>array_key_exists()</code>, but as said above, will return false if no value has been assigned. |
629
|
|
|
</p>', |
630
|
|
|
), |
631
|
|
|
), |
632
|
|
|
|
633
|
|
|
'isset_foo' => array( |
634
|
|
|
'title' => 'isset ( $x[\'foo\'] )', |
635
|
|
|
'url' => 'https://php.net/isset', |
636
|
|
|
'arg' => '$x', |
637
|
|
|
'function' => 'if ( ! is_object( $x ) ) { pr_bool( isset( $x[\'foo\'] ) ); } else { $class = get_class( $x ); trigger_error( \'Cannot use object of type \' . $class . \' as array\', E_USER_ERROR ); unset( $class ); }', |
638
|
|
|
'notes' => array( |
639
|
|
|
'<p> |
640
|
|
|
Whether to use <code>isset()</code> or <code>array_key_exists()</code> depends on what you want to know: |
641
|
|
|
</p> |
642
|
|
|
<ul> |
643
|
|
|
<li><code>isset( $array[$key] )</code> will tell you whether the array key exists <strong>and</strong> has been assigned a value.<br /> |
644
|
|
|
Used on its own it will give undesired results when used on strings as characters within a string can be approached using the <code>$x[]</code> syntax as well.<br /> |
645
|
|
|
Also, it will cause fatal errors when used on objects.</li> |
646
|
|
|
<li><code>array_key_exists( $key, $array )</code> will tell you only whether the array key exists, but will not check whether it has a value assigned to it.<br /> |
647
|
|
|
Used on its own, it will show a warning if $array is not an array</li> |
648
|
|
|
</ul> |
649
|
|
|
<p> |
650
|
|
|
This said, we can conclude that to avoid warnings and undesired results you will always have to use an <code>is_array()</code> first.<br /> |
651
|
|
|
Also note that <code>isset()</code> is faster than <code>array_key_exists()</code>, but as said above, will return false if no value has been assigned. |
652
|
|
|
</p>', |
653
|
|
|
), |
654
|
|
|
), |
655
|
|
|
|
656
|
|
|
'array_key_exists' => array( |
657
|
|
|
'title' => 'array_key_exists ( 0, $x )', |
658
|
|
|
'url' => 'https://php.net/array_key_exists', |
659
|
|
|
'arg' => '$x', |
660
|
|
|
'function' => 'if ( function_exists( \'array_key_exists\' ) ) { $r = array_key_exists( 0, $x ); if ( is_bool( $r ) ) { pr_bool( array_key_exists( 0, $x ) ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 4.0.7+)\n"; }', |
661
|
|
|
'notes' => array( |
662
|
|
|
'<p> |
663
|
|
|
Whether to use <code>isset()</code> or <code>array_key_exists()</code> depends on what you want to know: |
664
|
|
|
</p> |
665
|
|
|
<ul> |
666
|
|
|
<li><code>isset( $array[$key] )</code> will tell you whether the array key exists <strong>and</strong> has been assigned a value.<br /> |
667
|
|
|
Used on its own it will give undesired results when used on strings as characters within a string can be approached using the <code>$x[]</code> syntax as well.<br /> |
668
|
|
|
Also, it will cause fatal errors when used on objects.</li> |
669
|
|
|
<li><code>array_key_exists( $key, $array )</code> will tell you only whether the array key exists, but will not check whether it has a value assigned to it.<br /> |
670
|
|
|
Used on its own, it will show a warning if $array is not an array</li> |
671
|
|
|
</ul> |
672
|
|
|
<p> |
673
|
|
|
This said, we can conclude that to avoid warnings and undesired results you will always have to use an <code>is_array()</code> first.<br /> |
674
|
|
|
Also note that <code>isset()</code> is faster than <code>array_key_exists()</code>, but as said above, will return false if no value has been assigned. |
675
|
|
|
</p>', |
676
|
|
|
), |
677
|
|
|
|
678
|
|
|
), |
679
|
|
|
'in_array' => array( |
680
|
|
|
'title' => 'in_array ( \'s\', $x )', |
681
|
|
|
'url' => 'https://php.net/in_array', |
682
|
|
|
'arg' => '$x', |
683
|
|
|
'function' => 'pr_bool( in_array( \'s\', $x ) );', |
684
|
|
|
), |
685
|
|
|
'array_count_values' => array( |
686
|
|
|
'title' => 'array_count_values()', |
687
|
|
|
'url' => 'https://php.net/array_count_values', |
688
|
|
|
'arg' => '$x', |
689
|
|
|
'function' => 'pr_var( array_count_values( $x ), \'\', true, true );', |
690
|
|
|
), |
691
|
|
|
'array_access_simple_string' => array( |
692
|
|
|
'title' => '$x[\'foo\']', |
693
|
|
|
'url' => 'https://php.net/manual/en/language.types.array.php', |
694
|
|
|
'arg' => '$x', |
695
|
|
|
'function' => 'if ( ! is_object( $x ) ) { pr_var( $x[\'foo\'], \'\', true, true ); } else { $class = get_class( $x ); trigger_error( \'Cannot use object of type \' . $class . \' as array\', E_USER_ERROR ); unset( $class ); }', |
696
|
|
|
), |
697
|
|
|
'array_access_multi_string' => array( |
698
|
|
|
'title' => '$x[\'foo\'][\'bar\']', |
699
|
|
|
'url' => 'https://php.net/manual/en/language.types.array.php', |
700
|
|
|
'arg' => '$x', |
701
|
|
|
'function' => 'if ( ! is_object( $x ) ) { if ( ! is_string( $x ) || ( is_string( $x ) && ( PHP_VERSION_ID > 50350 || PHP_VERSION_ID < 50000 ) ) ) { pr_var( $x[\'foo\'][\'bar\'], \'\', true, true ); } else { trigger_error( \'Cannot use string offset as an array\', E_USER_ERROR ); } } else { $class = get_class( $x ); trigger_error( \'Cannot use object of type \' . $class . \' as array\', E_USER_ERROR ); unset( $class ); }', |
702
|
|
|
), |
703
|
|
|
|
704
|
|
|
|
705
|
|
|
'array_filter' => array( |
706
|
|
|
'title' => 'array_filter()', |
707
|
|
|
'url' => 'https://php.net/array_filter', |
708
|
|
|
'arg' => '$x', |
709
|
|
|
'function' => 'pr_var( array_filter( $x ), \'\', true, true );', |
710
|
|
|
), |
711
|
|
|
'array_flip' => array( |
712
|
|
|
'title' => 'array_flip()', |
713
|
|
|
'url' => 'https://php.net/array_flip', |
714
|
|
|
'arg' => '$x', |
715
|
|
|
'function' => 'pr_var( array_flip( $x ), \'\', true, true );', |
716
|
|
|
), |
717
|
|
|
'array_reverse' => array( |
718
|
|
|
'title' => 'array_reverse()', |
719
|
|
|
'url' => 'https://php.net/array_reverse', |
720
|
|
|
'arg' => '$x', |
721
|
|
|
'function' => 'pr_var( array_reverse( $x ), \'\', true, true );', |
722
|
|
|
), |
723
|
|
|
'current' => array( |
724
|
|
|
'title' => 'current()', |
725
|
|
|
'url' => 'https://php.net/current', |
726
|
|
|
'arg' => '$x', |
727
|
|
|
'function' => 'pr_var( current( $x ), \'\', true, true );', |
728
|
|
|
), |
729
|
|
|
'key' => array( |
730
|
|
|
'title' => 'key()', |
731
|
|
|
'url' => 'https://php.net/key', |
732
|
|
|
'arg' => '$x', |
733
|
|
|
'function' => 'pr_var( key( $x ), \'\', true, true );', |
734
|
|
|
), |
735
|
|
|
'shuffle' => array( |
736
|
|
|
'title' => 'shuffle ( $copy )', |
737
|
|
|
'url' => 'https://php.net/shuffle', |
738
|
|
|
'arg' => '$x', |
739
|
|
|
'function' => '$pass = shuffle( $x ); if ( $pass === true) { pr_var( $x, \'\', true, true ); } else { print \'FAILED\'; }', |
740
|
|
|
), |
741
|
|
|
'sort' => array( |
742
|
|
|
'title' => 'sort ( $copy )', |
743
|
|
|
'url' => 'https://php.net/sort', |
744
|
|
|
'arg' => '$x', |
745
|
|
|
'function' => '$pass = sort( $x ); if ( $pass === true) { pr_var( $x, \'\', true, true ); } else { print \'FAILED\'; }', |
746
|
|
|
), |
747
|
|
|
|
748
|
|
|
|
749
|
|
|
/* |
750
|
|
|
* Some object related functions. |
751
|
|
|
*/ |
752
|
|
|
'is_a' => array( |
753
|
|
|
'title' => 'is_a ( $x, \'TestObject\' )', |
754
|
|
|
'url' => 'https://php.net/is_a', |
755
|
|
|
'arg' => '$x', |
756
|
|
|
'function' => '$c = \'TestObject\'; $r = is_a( $x, $c ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
757
|
|
|
), |
758
|
|
|
'instanceof' => array( |
759
|
|
|
'title' => 'instanceof TestObject', |
760
|
|
|
'url' => 'https://php.net/language.operators.type', |
761
|
|
|
'arg' => '$x', |
762
|
|
|
'function' => 'print "E: not available (PHP 5.0+)\n";', // Note: has PHP5 equivalent in class.vartype-php5.php. |
763
|
|
|
), |
764
|
|
|
'get_class' => array( |
765
|
|
|
'title' => 'get_class()', |
766
|
|
|
'url' => 'https://php.net/get_class', |
767
|
|
|
'arg' => '$x', |
768
|
|
|
'function' => '$r = get_class( $x ); if ( ! is_bool( $r ) ) { pr_var( $r, \'\', true, true ); } else { pr_bool( $r ); }', |
769
|
|
|
), |
770
|
|
|
'get_parent_class' => array( |
771
|
|
|
'title' => 'get_parent_class()', |
772
|
|
|
'url' => 'https://php.net/get_parent_class', |
773
|
|
|
'arg' => '$x', |
774
|
|
|
'function' => '$r = get_parent_class( $x ); if ( ! is_bool( $r ) ) { pr_var( $r, \'\', true, true ); } else { pr_bool( $r ); }', |
775
|
|
|
), |
776
|
|
|
'is_subclass_of' => array( |
777
|
|
|
'title' => 'is_subclass_of ( $x, \'TestObject\' )', |
778
|
|
|
'url' => 'https://php.net/is_subclass_of', |
779
|
|
|
'arg' => '$x', |
780
|
|
|
'function' => '$c = \'TestObject\'; $r = is_subclass_of( $x, $c ); if ( is_bool( $r ) ) { pr_bool( $r, \'\', true, true ); } else { pr_var( $r, \'\', true, true ); }', |
781
|
|
|
), |
782
|
|
|
|
783
|
|
|
|
784
|
|
|
|
785
|
|
|
/* |
786
|
|
|
* Resource specific functions. |
787
|
|
|
*/ |
788
|
|
|
'get_resource_type' => array( |
789
|
|
|
'title' => 'get_resource_type()', |
790
|
|
|
'url' => 'https://php.net/get_resource_type', |
791
|
|
|
'arg' => '$x', |
792
|
|
|
'function' => 'if ( function_exists( \'get_resource_type\' ) ) { $r = get_resource_type( $x ); if ( is_string( $r ) ) { pr_str( $r ); } else if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); } } else {print "E: not available (PHP 4.0.2+)\n"; }', |
793
|
|
|
), |
794
|
|
|
|
795
|
|
|
|
796
|
|
|
|
797
|
|
|
|
798
|
|
|
|
799
|
|
|
|
800
|
|
|
/* |
801
|
|
|
* Test null comparisons. |
802
|
|
|
*/ |
803
|
|
|
'null_cmp_loose' => array( |
804
|
|
|
'title' => '== null', |
805
|
|
|
'arg' => '$x', |
806
|
|
|
'function' => 'pr_bool( $x == null );', |
807
|
|
|
), |
808
|
|
|
'null_cmp_strict' => array( |
809
|
|
|
'title' => '=== null', |
810
|
|
|
'arg' => '$x', |
811
|
|
|
'function' => 'pr_bool( $x === null );', |
812
|
|
|
), |
813
|
|
|
'null_cmp_loose_str' => array( |
814
|
|
|
'title' => '== \'null\'', |
815
|
|
|
'arg' => '$x', |
816
|
|
|
'function' => 'pr_bool( $x == \'null\' );', |
817
|
|
|
), |
818
|
|
|
'null_cmp_strict_str' => array( |
819
|
|
|
'title' => '=== \'null\'', |
820
|
|
|
'arg' => '$x', |
821
|
|
|
'function' => 'pr_bool( $x === \'null\' );', |
822
|
|
|
), |
823
|
|
|
|
824
|
|
|
'null_cmp_rv_loose' => array( |
825
|
|
|
'title' => 'null ==', |
826
|
|
|
'arg' => '$x', |
827
|
|
|
'function' => 'pr_bool( null == $x );', |
828
|
|
|
), |
829
|
|
|
'null_cmp_rv_strict' => array( |
830
|
|
|
'title' => 'null ===', |
831
|
|
|
'arg' => '$x', |
832
|
|
|
'function' => 'pr_bool( null === $x );', |
833
|
|
|
), |
834
|
|
|
'null_cmp_rv_loose_str' => array( |
835
|
|
|
'title' => '\'null\' ==', |
836
|
|
|
'arg' => '$x', |
837
|
|
|
'function' => 'pr_bool( \'null\' == $x );', |
838
|
|
|
), |
839
|
|
|
'null_cmp_rv_strict_str' => array( |
840
|
|
|
'title' => '\'null\' ===', |
841
|
|
|
'arg' => '$x', |
842
|
|
|
'function' => 'pr_bool( \'null\' === $x );', |
843
|
|
|
), |
844
|
|
|
|
845
|
|
|
|
846
|
|
|
/* |
847
|
|
|
* Boolean comparisons. |
848
|
|
|
*/ |
849
|
|
|
'bool_cmp_true_loose' => array( |
850
|
|
|
'title' => '== true', |
851
|
|
|
'arg' => '$x', |
852
|
|
|
'function' => 'pr_bool( $x == true );', |
853
|
|
|
), |
854
|
|
|
'bool_cmp_false_loose' => array( |
855
|
|
|
'title' => '== false', |
856
|
|
|
'arg' => '$x', |
857
|
|
|
'function' => 'pr_bool( $x == false );', |
858
|
|
|
), |
859
|
|
|
'bool_cmp_true_strict' => array( |
860
|
|
|
'title' => '=== true', |
861
|
|
|
'arg' => '$x', |
862
|
|
|
'function' => 'pr_bool( $x === true );', |
863
|
|
|
), |
864
|
|
|
'bool_cmp_false_strict' => array( |
865
|
|
|
'title' => '=== false', |
866
|
|
|
'arg' => '$x', |
867
|
|
|
'function' => 'pr_bool( $x === false );', |
868
|
|
|
), |
869
|
|
|
'bool_cmp_true_loose_int' => array( |
870
|
|
|
'title' => '== 1', |
871
|
|
|
'arg' => '$x', |
872
|
|
|
'function' => 'pr_bool( $x == 1 );', |
873
|
|
|
), |
874
|
|
|
'bool_cmp_false_loose_int' => array( |
875
|
|
|
'title' => '== 0', |
876
|
|
|
'arg' => '$x', |
877
|
|
|
'function' => 'pr_bool( $x == 0 );', |
878
|
|
|
), |
879
|
|
|
'bool_cmp_true_strict_int' => array( |
880
|
|
|
'title' => '=== 1', |
881
|
|
|
'arg' => '$x', |
882
|
|
|
'function' => 'pr_bool( $x === 1 );', |
883
|
|
|
), |
884
|
|
|
'bool_cmp_false_strict_int' => array( |
885
|
|
|
'title' => '=== 0', |
886
|
|
|
'arg' => '$x', |
887
|
|
|
'function' => 'pr_bool( $x === 0 );', |
888
|
|
|
), |
889
|
|
|
'bool_cmp_true_loose_str' => array( |
890
|
|
|
'title' => '== \'true\'', |
891
|
|
|
'arg' => '$x', |
892
|
|
|
'function' => 'pr_bool( $x == \'true\' );', |
893
|
|
|
), |
894
|
|
|
'bool_cmp_false_loose_str' => array( |
895
|
|
|
'title' => '== \'false\'', |
896
|
|
|
'arg' => '$x', |
897
|
|
|
'function' => 'pr_bool( $x == \'false\' );', |
898
|
|
|
), |
899
|
|
|
'bool_cmp_true_strict_str' => array( |
900
|
|
|
'title' => '=== \'true\'', |
901
|
|
|
'arg' => '$x', |
902
|
|
|
'function' => 'pr_bool( $x === \'true\' );', |
903
|
|
|
), |
904
|
|
|
'bool_cmp_false_strict_str' => array( |
905
|
|
|
'title' => '=== \'false\'', |
906
|
|
|
'arg' => '$x', |
907
|
|
|
'function' => 'pr_bool( $x === \'false\' );', |
908
|
|
|
), |
909
|
|
|
|
910
|
|
|
|
911
|
|
|
|
912
|
|
|
'bool_cmp_rv_true_loose' => array( |
913
|
|
|
'title' => 'true ==', |
914
|
|
|
'arg' => '$x', |
915
|
|
|
'function' => 'pr_bool( true == $x );', |
916
|
|
|
), |
917
|
|
|
'bool_cmp_rv_false_loose' => array( |
918
|
|
|
'title' => 'false ==', |
919
|
|
|
'arg' => '$x', |
920
|
|
|
'function' => 'pr_bool( false == $x );', |
921
|
|
|
), |
922
|
|
|
'bool_cmp_rv_true_strict' => array( |
923
|
|
|
'title' => 'true ===', |
924
|
|
|
'arg' => '$x', |
925
|
|
|
'function' => 'pr_bool( true === $x );', |
926
|
|
|
), |
927
|
|
|
'bool_cmp_rv_false_strict' => array( |
928
|
|
|
'title' => 'false ===', |
929
|
|
|
'arg' => '$x', |
930
|
|
|
'function' => 'pr_bool( false === $x );', |
931
|
|
|
), |
932
|
|
|
'bool_cmp_rv_true_loose_int' => array( |
933
|
|
|
'title' => '1 ==', |
934
|
|
|
'arg' => '$x', |
935
|
|
|
'function' => 'pr_bool( 1 == $x );', |
936
|
|
|
), |
937
|
|
|
'bool_cmp_rv_false_loose_int' => array( |
938
|
|
|
'title' => '0 ==', |
939
|
|
|
'arg' => '$x', |
940
|
|
|
'function' => 'pr_bool( 0 == $x );', |
941
|
|
|
), |
942
|
|
|
'bool_cmp_rv_true_strict_int' => array( |
943
|
|
|
'title' => '1 ===', |
944
|
|
|
'arg' => '$x', |
945
|
|
|
'function' => 'pr_bool( 1 === $x );', |
946
|
|
|
), |
947
|
|
|
'bool_cmp_rv_false_strict_int' => array( |
948
|
|
|
'title' => '0 ===', |
949
|
|
|
'arg' => '$x', |
950
|
|
|
'function' => 'pr_bool( 0 === $x );', |
951
|
|
|
), |
952
|
|
|
'bool_cmp_rv_true_loose_str' => array( |
953
|
|
|
'title' => '\'true\' ==', |
954
|
|
|
'arg' => '$x', |
955
|
|
|
'function' => 'pr_bool( \'true\' == $x );', |
956
|
|
|
), |
957
|
|
|
'bool_cmp_rv_false_loose_str' => array( |
958
|
|
|
'title' => '\'false\' ==', |
959
|
|
|
'arg' => '$x', |
960
|
|
|
'function' => 'pr_bool( \'false\' == $x );', |
961
|
|
|
), |
962
|
|
|
'bool_cmp_rv_true_strict_str' => array( |
963
|
|
|
'title' => '\'true\' ===', |
964
|
|
|
'arg' => '$x', |
965
|
|
|
'function' => 'pr_bool( \'true\' === $x );', |
966
|
|
|
), |
967
|
|
|
'bool_cmp_rv_false_strict_str' => array( |
968
|
|
|
'title' => '\'false\' ===', |
969
|
|
|
'arg' => '$x', |
970
|
|
|
'function' => 'pr_bool( \'false\' === $x );', |
971
|
|
|
), |
972
|
|
|
|
973
|
|
|
|
974
|
|
|
/* |
975
|
|
|
* Comparisons with int 0. |
976
|
|
|
*/ |
977
|
|
|
'int_cmp_gt0' => array( |
978
|
|
|
'title' => '> 0', |
979
|
|
|
'arg' => '$x', |
980
|
|
|
'function' => 'pr_bool( $x > 0 );', |
981
|
|
|
), |
982
|
|
|
'int_cmp_gte0' => array( |
983
|
|
|
'title' => '>= 0', |
984
|
|
|
'arg' => '$x', |
985
|
|
|
'function' => 'pr_bool( $x >= 0 );', |
986
|
|
|
), |
987
|
|
|
'int_cmp_is0_loose' => array( |
988
|
|
|
'title' => '== 0', |
989
|
|
|
'arg' => '$x', |
990
|
|
|
'function' => 'pr_bool( $x == 0 );', |
991
|
|
|
), |
992
|
|
|
'int_cmp_is0_strict' => array( |
993
|
|
|
'title' => '=== 0', |
994
|
|
|
'arg' => '$x', |
995
|
|
|
'function' => 'pr_bool( $x === 0 );', |
996
|
|
|
), |
997
|
|
|
'int_cmp_not0_loose' => array( |
998
|
|
|
'title' => '!= 0', |
999
|
|
|
'arg' => '$x', |
1000
|
|
|
'function' => 'pr_bool( $x != 0 );', |
1001
|
|
|
), |
1002
|
|
|
'int_cmp_not0_strict' => array( |
1003
|
|
|
'title' => '!== 0', |
1004
|
|
|
'arg' => '$x', |
1005
|
|
|
'function' => 'pr_bool( $x !== 0 );', |
1006
|
|
|
), |
1007
|
|
|
'int_cmp_lt0' => array( |
1008
|
|
|
'title' => '< 0', |
1009
|
|
|
'arg' => '$x', |
1010
|
|
|
'function' => 'pr_bool( $x < 0 );', |
1011
|
|
|
), |
1012
|
|
|
'int_cmp_lte0' => array( |
1013
|
|
|
'title' => '<= 0', |
1014
|
|
|
'arg' => '$x', |
1015
|
|
|
'function' => 'pr_bool( $x <= 0 );', |
1016
|
|
|
), |
1017
|
|
|
|
1018
|
|
|
|
1019
|
|
|
/* |
1020
|
|
|
* Comparisons with empty string. |
1021
|
|
|
*/ |
1022
|
|
|
'str_cmp_empty_loose' => array( |
1023
|
|
|
'title' => '== \'\'', |
1024
|
|
|
'arg' => '$x', |
1025
|
|
|
'function' => 'pr_bool( $x == \'\' );', |
1026
|
|
|
), |
1027
|
|
|
'str_cmp_empty_strict' => array( |
1028
|
|
|
'title' => '=== \'\'', |
1029
|
|
|
'arg' => '$x', |
1030
|
|
|
'function' => 'pr_bool( $x === \'\' );', |
1031
|
|
|
), |
1032
|
|
|
'str_cmp_not_empty_loose' => array( |
1033
|
|
|
'title' => '!= \'\'', |
1034
|
|
|
'arg' => '$x', |
1035
|
|
|
'function' => 'pr_bool( $x != \'\' );', |
1036
|
|
|
), |
1037
|
|
|
'str_cmp_not_empty_strict' => array( |
1038
|
|
|
'title' => '!== \'\'', |
1039
|
|
|
'arg' => '$x', |
1040
|
|
|
'function' => 'pr_bool( $x !== \'\' );', |
1041
|
|
|
), |
1042
|
|
|
|
1043
|
|
|
|
1044
|
|
|
/* |
1045
|
|
|
* Arithmetic operations. |
1046
|
|
|
*/ |
1047
|
|
|
'pre_increment' => array( |
1048
|
|
|
'title' => '$x = ++$x', |
1049
|
|
|
'url' => 'https://php.net/language.operators.increment', |
1050
|
|
|
'arg' => '$x', |
1051
|
|
|
'function' => '$r = ++$x; if ( is_int( $r ) ) { pr_int( $r ); } else if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1052
|
|
|
'notes' => array( |
1053
|
|
|
'<p>Please take note: using the in-/decrementors on SplInt and SplFloat objects may give unexpected (inconsistent) results....</p>', |
1054
|
|
|
), |
1055
|
|
|
), |
1056
|
|
|
'post_increment' => array( |
1057
|
|
|
'title' => '$x = $x++', |
1058
|
|
|
'url' => 'https://php.net/language.operators.increment', |
1059
|
|
|
'arg' => '$x', |
1060
|
|
|
'function' => '$r = $x++; if ( is_int( $r ) ) { pr_int( $r ); } else if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1061
|
|
|
'notes' => array( |
1062
|
|
|
'<p>Please take note: using the in-/decrementors on SplInt and SplFloat objects may give unexpected (inconsistent) results....</p>', |
1063
|
|
|
), |
1064
|
|
|
), |
1065
|
|
|
'pre_decrement' => array( |
1066
|
|
|
'title' => '$x = --$x', |
1067
|
|
|
'url' => 'https://php.net/language.operators.increment', |
1068
|
|
|
'arg' => '$x', |
1069
|
|
|
'function' => '$r = --$x; if ( is_int( $r ) ) { pr_int( $r ); } else if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1070
|
|
|
'notes' => array( |
1071
|
|
|
'<p>Please take note: using the in-/decrementors on SplInt and SplFloat objects may give unexpected (inconsistent) results....</p>', |
1072
|
|
|
), |
1073
|
|
|
), |
1074
|
|
|
'post_decrement' => array( |
1075
|
|
|
'title' => '$x = $x--', |
1076
|
|
|
'url' => 'https://php.net/language.operators.increment', |
1077
|
|
|
'arg' => '$x', |
1078
|
|
|
'function' => '$r = $x--; if ( is_int( $r ) ) { pr_int( $r ); } else if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1079
|
|
|
'notes' => array( |
1080
|
|
|
'<p>Please take note: using the in-/decrementors on SplInt and SplFloat objects may give unexpected (inconsistent) results....</p>', |
1081
|
|
|
), |
1082
|
|
|
), |
1083
|
|
|
|
1084
|
|
|
|
1085
|
|
|
'arithmetic_negate' => array( |
1086
|
|
|
'title' => '-$x', |
1087
|
|
|
'url' => 'https://php.net/language.operators.arithmetic', |
1088
|
|
|
'arg' => '$x', |
1089
|
|
|
'function' => 'if ( ! is_array( $x ) && ( PHP_VERSION_ID > 50005 || ! is_object( $x ) ) ) { pr_var( -$x, \'\', true, true ); } else { trigger_error( \'Unsupported operand types\', E_USER_ERROR ); }', |
1090
|
|
|
), |
1091
|
|
|
'arithmetic_subtract' => array( |
1092
|
|
|
'title' => '$x - 0', |
1093
|
|
|
'url' => 'https://php.net/language.operators.arithmetic', |
1094
|
|
|
'arg' => '$x', |
1095
|
|
|
'function' => 'if ( ! is_array( $x ) && ( PHP_VERSION_ID > 50005 || ! is_object( $x ) ) ) { pr_var( $x - 0, \'\', true, true ); } else { trigger_error( \'Unsupported operand types\', E_USER_ERROR ); }', |
1096
|
|
|
), |
1097
|
|
|
'arithmetic_multiply' => array( |
1098
|
|
|
'title' => '$x * 1', |
1099
|
|
|
'url' => 'https://php.net/language.operators.arithmetic', |
1100
|
|
|
'arg' => '$x', |
1101
|
|
|
'function' => 'if ( ! is_array( $x ) && ( PHP_VERSION_ID > 50005 || ! is_object( $x ) ) ) { pr_var( $x * 1, \'\', true, true ); } else { trigger_error( \'Unsupported operand types\', E_USER_ERROR ); }', |
1102
|
|
|
), |
1103
|
|
|
'arithmetic_divide' => array( |
1104
|
|
|
'title' => '$x / 1', |
1105
|
|
|
'url' => 'https://php.net/language.operators.arithmetic', |
1106
|
|
|
'arg' => '$x', |
1107
|
|
|
'function' => 'if ( ! is_array( $x ) && ( PHP_VERSION_ID > 50005 || ! is_object( $x ) ) ) { pr_var( $x / 1, \'\', true, true ); } else { trigger_error( \'Unsupported operand types\', E_USER_ERROR ); }', |
1108
|
|
|
), |
1109
|
|
|
'arithmetic_modulus' => array( |
1110
|
|
|
'title' => '$x % 1', |
1111
|
|
|
'url' => 'https://php.net/language.operators.arithmetic', |
1112
|
|
|
'arg' => '$x', |
1113
|
|
|
'function' => 'pr_var( $x % 1, \'\', true, true );', |
1114
|
|
|
), |
1115
|
|
|
|
1116
|
|
|
|
1117
|
|
|
/* |
1118
|
|
|
* Tests using preg_match(). |
1119
|
|
|
*/ |
1120
|
|
|
'preg_int_pos' => array( |
1121
|
|
|
'title' => 'preg_match (`^[0-9]+$`)', |
1122
|
|
|
'url' => 'https://php.net/preg-match', |
1123
|
|
|
'arg' => '$x', |
1124
|
|
|
'function' => '$valid = preg_match( \'`^[0-9]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1125
|
|
|
), |
1126
|
|
|
'preg_int' => array( |
1127
|
|
|
'title' => 'preg_match (`^[0-9<span style="color: red;">-</span>]+$`)', |
1128
|
|
|
'url' => 'https://php.net/preg-match', |
1129
|
|
|
'arg' => '$x', |
1130
|
|
|
'function' => '$valid = preg_match( \'`^[0-9-]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1131
|
|
|
), |
1132
|
|
|
// Results depend on locale. |
1133
|
|
|
'preg_digit_pos' => array( |
1134
|
|
|
'title' => 'preg_match (`^\d+$`)', |
1135
|
|
|
'url' => 'https://php.net/preg-match', |
1136
|
|
|
'arg' => '$x', |
1137
|
|
|
'function' => '$valid = preg_match( \'`^\d+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1138
|
|
|
), |
1139
|
|
|
// Results depend on locale. |
1140
|
|
|
'preg_digit' => array( |
1141
|
|
|
'title' => 'preg_match (`^[\d<span style="color: red;">-</span>]+$`)', |
1142
|
|
|
'url' => 'https://php.net/preg-match', |
1143
|
|
|
'arg' => '$x', |
1144
|
|
|
'function' => '$valid = preg_match( \'`^[\d-]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1145
|
|
|
), |
1146
|
|
|
|
1147
|
|
|
|
1148
|
|
|
// ##PREG_DECIMAL_POINT## is replaced by the locale specific decimal point character in the class constructor. |
1149
|
|
|
'preg_float_pos' => array( |
1150
|
|
|
'title' => 'preg_match (`^[0-9##PREG_DECIMAL_POINT##]+$`)', |
1151
|
|
|
'tooltip' => 'Decimal point character adjusted based on locale', |
1152
|
|
|
'url' => 'https://php.net/preg-match', |
1153
|
|
|
'arg' => '$x', |
1154
|
|
|
'function' => '$valid = preg_match( \'`^[0-9##PREG_DECIMAL_POINT##]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1155
|
|
|
), |
1156
|
|
|
// ##PREG_DECIMAL_POINT## is replaced by the locale specific decimal point character in the class constructor. |
1157
|
|
|
'preg_float' => array( |
1158
|
|
|
'title' => 'preg_match (`^[0-9##PREG_DECIMAL_POINT##<span style="color: red;">-</span>]+$`)', |
1159
|
|
|
'tooltip' => 'Decimal point character adjusted based on locale', |
1160
|
|
|
'url' => 'https://php.net/preg-match', |
1161
|
|
|
'arg' => '$x', |
1162
|
|
|
'function' => '$valid = preg_match( \'`^[0-9##PREG_DECIMAL_POINT##-]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1163
|
|
|
), |
1164
|
|
|
// ##PREG_DECIMAL_POINT## is replaced by the locale specific decimal point character in the class constructor. |
1165
|
|
|
// Results depend on locale. |
1166
|
|
|
'preg_digit_float_pos' => array( |
1167
|
|
|
'title' => 'preg_match (`^[\d##PREG_DECIMAL_POINT##]+$`)', |
1168
|
|
|
'tooltip' => 'Decimal point character adjusted based on locale', |
1169
|
|
|
'url' => 'https://php.net/preg-match', |
1170
|
|
|
'arg' => '$x', |
1171
|
|
|
'function' => '$valid = preg_match( \'`^[\d##PREG_DECIMAL_POINT##]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1172
|
|
|
), |
1173
|
|
|
// ##PREG_DECIMAL_POINT## is replaced by the locale specific decimal point character in the class constructor. |
1174
|
|
|
// Results depend on locale. |
1175
|
|
|
'preg_digit_float' => array( |
1176
|
|
|
'title' => 'preg_match (`^[\d##PREG_DECIMAL_POINT##<span style="color: red;">-</span>]]+$`)', |
1177
|
|
|
'tooltip' => 'Decimal point character adjusted based on locale', |
1178
|
|
|
'url' => 'https://php.net/preg-match', |
1179
|
|
|
'arg' => '$x', |
1180
|
|
|
'function' => '$valid = preg_match( \'`^[\d##PREG_DECIMAL_POINT##-]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1181
|
|
|
), |
1182
|
|
|
'preg_alpha' => array( |
1183
|
|
|
'title' => 'preg_match (`^[A-Za-z]+$`)', |
1184
|
|
|
'url' => 'https://php.net/preg-match', |
1185
|
|
|
'arg' => '$x', |
1186
|
|
|
'function' => '$valid = preg_match( \'`^[A-Za-z]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1187
|
|
|
), |
1188
|
|
|
'preg_alnum' => array( |
1189
|
|
|
'title' => 'preg_match (`^[A-Za-z0-9]+$`)', |
1190
|
|
|
'url' => 'https://php.net/preg-match', |
1191
|
|
|
'arg' => '$x', |
1192
|
|
|
'function' => '$valid = preg_match( \'`^[A-Za-z0-9]+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1193
|
|
|
), |
1194
|
|
|
'preg_word' => array( |
1195
|
|
|
'title' => 'preg_match (`^\w+$`)', |
1196
|
|
|
'url' => 'https://php.net/preg-match', |
1197
|
|
|
'arg' => '$x', |
1198
|
|
|
'function' => '$valid = preg_match( \'`^\w+$`\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1199
|
|
|
), |
1200
|
|
|
// Result depends on locale. |
1201
|
|
|
'preg_word_utf8' => array( |
1202
|
|
|
'title' => 'preg_match (`^\w+$`u)', |
1203
|
|
|
'url' => 'https://php.net/preg-match', |
1204
|
|
|
'arg' => '$x', |
1205
|
|
|
'function' => '$valid = preg_match( \'`^\w+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); }', |
1206
|
|
|
'notes' => array( |
1207
|
|
|
'<p>What <code>\w</code> matches is locale dependent. The locale for these cheatsheets are set to <code>C</code>. Results with other locales will vary.</p>', |
1208
|
|
|
), |
1209
|
|
|
), |
1210
|
|
|
|
1211
|
|
|
|
1212
|
|
|
|
1213
|
|
|
'preg_int_unicode_pos' => array( |
1214
|
|
|
'title' => 'preg_match (`^\p{N}+$`u)', |
1215
|
|
|
'url' => 'https://php.net/regexp.reference.unicode.php', |
1216
|
|
|
'arg' => '$x', |
1217
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50100 ) { $valid = preg_match( \'`^\p{N}+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); } } else { print "E: not available (PHP 5.1+)\n"; }', |
1218
|
|
|
), |
1219
|
|
|
'preg_int_unicode' => array( |
1220
|
|
|
'title' => 'preg_match (`^[\p{N}-]+$`u)', |
1221
|
|
|
'url' => 'https://php.net/regexp.reference.unicode.php', |
1222
|
|
|
'arg' => '$x', |
1223
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50100 ) { $valid = preg_match( \'`^[\p{N}-]+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); } } else { print "E: not available (PHP 5.1+)\n"; }', |
1224
|
|
|
), |
1225
|
|
|
// ##PREG_DECIMAL_POINT## is replaced by the locale specific decimal point character in the class constructor. |
1226
|
|
|
'preg_number_unicode_pos' => array( |
1227
|
|
|
'title' => 'preg_match (`^[\p{N}##PREG_DECIMAL_POINT##]+$`u)', |
1228
|
|
|
'url' => 'https://php.net/regexp.reference.unicode.php', |
1229
|
|
|
'arg' => '$x', |
1230
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50100 ) { $valid = preg_match( \'`^[\p{N}##PREG_DECIMAL_POINT##]+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); } } else { print "E: not available (PHP 5.1+)\n"; }', |
1231
|
|
|
), |
1232
|
|
|
// ##PREG_DECIMAL_POINT## is replaced by the locale specific decimal point character in the class constructor. |
1233
|
|
|
'preg_number_unicode' => array( |
1234
|
|
|
'title' => 'preg_match (`^[\p{N}##PREG_DECIMAL_POINT##-]+$`u)', |
1235
|
|
|
'url' => 'https://php.net/regexp.reference.unicode.php', |
1236
|
|
|
'arg' => '$x', |
1237
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50100 ) { $valid = preg_match( \'`^[\p{N}##PREG_DECIMAL_POINT##-]+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); } } else { print "E: not available (PHP 5.1+)\n"; }', |
1238
|
|
|
), |
1239
|
|
|
|
1240
|
|
|
'preg_alpha_unicode' => array( |
1241
|
|
|
'title' => 'preg_match (`^\p{L}+$`u)', |
1242
|
|
|
'url' => 'https://php.net/regexp.reference.unicode.php', |
1243
|
|
|
'arg' => '$x', |
1244
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50100 ) { $valid = preg_match( \'`^\p{L}+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); } } else { print "E: not available (PHP 5.1+)\n"; }', |
1245
|
|
|
), |
1246
|
|
|
'preg_alnum_unicode' => array( |
1247
|
|
|
'title' => 'preg_match (`^[\p{L}\p{N}]+$`u)', |
1248
|
|
|
'url' => 'https://php.net/regexp.reference.unicode.php', |
1249
|
|
|
'arg' => '$x', |
1250
|
|
|
'function' => 'if ( PHP_VERSION_ID >= 50100 ) { $valid = preg_match( \'`^[\p{L}\p{N}]+$`u\', $x ); if ( $valid === 1 ) { pr_bool( true ); } else if ( $valid === 0 ) { pr_bool( false ); } else if ( $valid === false ) { print \'Error\'; } else { pr_var( $valid, \'\', true, true ); } } else { print "E: not available (PHP 5.1+)\n"; }', |
1251
|
|
|
), |
1252
|
|
|
|
1253
|
|
|
|
1254
|
|
|
/* |
1255
|
|
|
* CTYPE extension. |
1256
|
|
|
*/ |
1257
|
|
|
'ctype_alnum' => array( |
1258
|
|
|
'title' => 'ctype_alnum()', |
1259
|
|
|
'url' => 'https://php.net/ctype_alnum', |
1260
|
|
|
'arg' => '$x', |
1261
|
|
|
'function' => '$r = ctype_alnum( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1262
|
|
|
'notes' => array( |
1263
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1264
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1265
|
|
|
), |
1266
|
|
|
), |
1267
|
|
|
'ctype_alpha' => array( |
1268
|
|
|
'title' => 'ctype_alpha()', |
1269
|
|
|
'url' => 'https://php.net/ctype_alpha', |
1270
|
|
|
'arg' => '$x', |
1271
|
|
|
'function' => '$r = ctype_alpha( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1272
|
|
|
'notes' => array( |
1273
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1274
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1275
|
|
|
), |
1276
|
|
|
|
1277
|
|
|
), |
1278
|
|
|
'ctype_cntrl' => array( |
1279
|
|
|
'title' => 'ctype_cntrl()', |
1280
|
|
|
'url' => 'https://php.net/ctype_cntrl', |
1281
|
|
|
'arg' => '$x', |
1282
|
|
|
'function' => '$r = ctype_cntrl( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1283
|
|
|
'notes' => array( |
1284
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1285
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1286
|
|
|
), |
1287
|
|
|
|
1288
|
|
|
), |
1289
|
|
|
'ctype_digit' => array( |
1290
|
|
|
'title' => 'ctype_digit()', |
1291
|
|
|
'url' => 'https://php.net/ctype_digit', |
1292
|
|
|
'arg' => '$x', |
1293
|
|
|
'function' => '$r = ctype_digit( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1294
|
|
|
'notes' => array( |
1295
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1296
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1297
|
|
|
), |
1298
|
|
|
|
1299
|
|
|
), |
1300
|
|
|
'ctype_graph' => array( |
1301
|
|
|
'title' => 'ctype_graph()', |
1302
|
|
|
'url' => 'https://php.net/ctype_graph', |
1303
|
|
|
'arg' => '$x', |
1304
|
|
|
'function' => '$r = ctype_graph( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1305
|
|
|
'notes' => array( |
1306
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1307
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1308
|
|
|
), |
1309
|
|
|
|
1310
|
|
|
), |
1311
|
|
|
'ctype_lower' => array( |
1312
|
|
|
'title' => 'ctype_lower()', |
1313
|
|
|
'url' => 'https://php.net/ctype_lower', |
1314
|
|
|
'arg' => '$x', |
1315
|
|
|
'function' => '$r = ctype_lower( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1316
|
|
|
'notes' => array( |
1317
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1318
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1319
|
|
|
), |
1320
|
|
|
|
1321
|
|
|
), |
1322
|
|
|
'ctype_print' => array( |
1323
|
|
|
'title' => 'ctype_print()', |
1324
|
|
|
'url' => 'https://php.net/ctype_print', |
1325
|
|
|
'arg' => '$x', |
1326
|
|
|
'function' => '$r = ctype_print( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1327
|
|
|
'notes' => array( |
1328
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1329
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1330
|
|
|
), |
1331
|
|
|
|
1332
|
|
|
), |
1333
|
|
|
'ctype_punct' => array( |
1334
|
|
|
'title' => 'ctype_punct()', |
1335
|
|
|
'url' => 'https://php.net/ctype_punct', |
1336
|
|
|
'arg' => '$x', |
1337
|
|
|
'function' => '$r = ctype_punct( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1338
|
|
|
'notes' => array( |
1339
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1340
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1341
|
|
|
), |
1342
|
|
|
|
1343
|
|
|
), |
1344
|
|
|
'ctype_space' => array( |
1345
|
|
|
'title' => 'ctype_space()', |
1346
|
|
|
'url' => 'https://php.net/ctype_space', |
1347
|
|
|
'arg' => '$x', |
1348
|
|
|
'function' => '$r = ctype_space( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1349
|
|
|
'notes' => array( |
1350
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1351
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1352
|
|
|
), |
1353
|
|
|
|
1354
|
|
|
), |
1355
|
|
|
'ctype_upper' => array( |
1356
|
|
|
'title' => 'ctype_upper()', |
1357
|
|
|
'url' => 'https://php.net/ctype_upper', |
1358
|
|
|
'arg' => '$x', |
1359
|
|
|
'function' => '$r = ctype_upper( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1360
|
|
|
'notes' => array( |
1361
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1362
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1363
|
|
|
), |
1364
|
|
|
|
1365
|
|
|
), |
1366
|
|
|
'ctype_xdigit' => array( |
1367
|
|
|
'title' => 'ctype_xdigit()', |
1368
|
|
|
'url' => 'https://php.net/ctype_xdigit', |
1369
|
|
|
'arg' => '$x', |
1370
|
|
|
'function' => '$r = ctype_xdigit( $x ); if ( is_bool( $r ) ) { pr_bool( $r ); } else { pr_var( $r, \'\', true, true ); }', |
1371
|
|
|
'notes' => array( |
1372
|
|
|
'<p><strong>Important</strong>: Integers between -128 and 255 are interpreted as the ASCII value pointing to a character (negative values have 256 added in order to allow characters in the Extended ASCII range).<br /> |
1373
|
|
|
In any other case, integers are interpreted as a string containing the decimal digits of the integer.</p>', |
1374
|
|
|
), |
1375
|
|
|
|
1376
|
|
|
), |
1377
|
|
|
|
1378
|
|
|
|
1379
|
|
|
|
1380
|
|
|
|
1381
|
|
|
|
1382
|
|
|
|
1383
|
|
|
/* |
1384
|
|
|
* FILTER extension. |
1385
|
|
|
*/ |
1386
|
|
|
|
1387
|
|
|
// Boolean filters. |
1388
|
|
|
'filter_var_bool' => array( |
1389
|
|
|
'title' => 'filter_var (…)', |
1390
|
|
|
'tooltip' => 'filter_var( $x, FILTER_VALIDATE_BOOLEAN )', |
1391
|
|
|
'url' => 'https://php.net/filter_var', |
1392
|
|
|
'arg' => '$x', |
1393
|
|
|
'function' => 'if ( function_exists( \'filter_var\' ) ) { pr_bool( filter_var( $x, FILTER_VALIDATE_BOOLEAN ), \'\', true, true ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1394
|
|
|
), |
1395
|
|
|
'filter_var_array_bool' => array( |
1396
|
|
|
'title' => 'filter_var_array (…)', |
1397
|
|
|
'tooltip' => 'filter_var_array( $x, FILTER_VALIDATE_BOOLEAN )', |
1398
|
|
|
'url' => 'https://php.net/filter_var_array', |
1399
|
|
|
'arg' => '$x', |
1400
|
|
|
'function' => 'if ( function_exists( \'filter_var_array\' ) ) { pr_var( filter_var_array( $x, FILTER_VALIDATE_BOOLEAN ), \'\', true, true ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1401
|
|
|
), |
1402
|
|
|
'filter_combined_bool' => array( |
1403
|
|
|
'title' => 'filter_var (…)', |
1404
|
|
|
'tooltip' => ' |
1405
|
|
|
if( ! is_array( $x ) ) { |
1406
|
|
|
filter_var( $x, FILTER_VALIDATE_BOOLEAN ); |
1407
|
|
|
} |
1408
|
|
|
else { |
1409
|
|
|
filter_var_array( $x, FILTER_VALIDATE_BOOLEAN ); |
1410
|
|
|
} |
1411
|
|
|
', |
1412
|
|
|
'url' => 'https://php.net/filter_var', |
1413
|
|
|
'arg' => '$x', |
1414
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'bool\', FILTER_VALIDATE_BOOLEAN ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1415
|
|
|
), |
1416
|
|
|
'filter_combined_bool_null' => array( |
1417
|
|
|
'title' => 'filter_var (…)', |
1418
|
|
|
'tooltip' => ' |
1419
|
|
|
if( ! is_array( $x ) ) { |
1420
|
|
|
filter_var( $x, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ); |
1421
|
|
|
} |
1422
|
|
|
else { |
1423
|
|
|
filter_var_array( $x, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1424
|
|
|
} |
1425
|
|
|
', |
1426
|
|
|
'url' => 'https://php.net/filter_var', |
1427
|
|
|
'arg' => '$x', |
1428
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'bool\', FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1429
|
|
|
'notes' => array( |
1430
|
|
|
'<p>Please note: On some PHP versions <code>filter_var( $x, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE )</code> where <code>$x = false</code> will incorrectly return <code>null</code>.<br /> |
1431
|
|
|
Also: with the same parameters filter_var() will return <code>false</code> instead of <code>null</code> for most objects.</p>', |
1432
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1433
|
|
|
), |
1434
|
|
|
), |
1435
|
|
|
|
1436
|
|
|
// Float filters. |
1437
|
|
|
'filter_var_float' => array( |
1438
|
|
|
'title' => 'filter_var (…)', |
1439
|
|
|
'tooltip' => 'filter_var( $x, FILTER_VALIDATE_FLOAT )', |
1440
|
|
|
'url' => 'https://php.net/filter_var', |
1441
|
|
|
'arg' => '$x', |
1442
|
|
|
'function' => 'if ( function_exists( \'filter_var\' ) ) { $r = filter_var( $x, FILTER_VALIDATE_FLOAT ); if ( is_float( $r ) ) { pr_flt( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1443
|
|
|
), |
1444
|
|
|
'filter_var_array_float' => array( |
1445
|
|
|
'title' => 'filter_var_array (…)', |
1446
|
|
|
'tooltip' => 'filter_var_array( $x, FILTER_VALIDATE_FLOAT )', |
1447
|
|
|
'url' => 'https://php.net/filter_var_array', |
1448
|
|
|
'arg' => '$x', |
1449
|
|
|
'function' => 'if ( function_exists( \'filter_var_array\' ) ) { pr_var( filter_var_array( $x, FILTER_VALIDATE_FLOAT ), \'\', true, true ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1450
|
|
|
), |
1451
|
|
|
'filter_combined_float' => array( |
1452
|
|
|
'title' => 'filter_var (…)', |
1453
|
|
|
'tooltip' => ' |
1454
|
|
|
if( ! is_array( $x ) ) { |
1455
|
|
|
filter_var( $x, FILTER_VALIDATE_FLOAT ); |
1456
|
|
|
} |
1457
|
|
|
else { |
1458
|
|
|
filter_var_array( $x, FILTER_VALIDATE_FLOAT ); |
1459
|
|
|
} |
1460
|
|
|
', |
1461
|
|
|
'url' => 'https://php.net/filter_var', |
1462
|
|
|
'arg' => '$x', |
1463
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'float\', FILTER_VALIDATE_FLOAT ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1464
|
|
|
), |
1465
|
|
|
'filter_combined_float_null' => array( |
1466
|
|
|
'title' => 'filter_var (…)', |
1467
|
|
|
'tooltip' => ' |
1468
|
|
|
if( ! is_array( $x ) ) { |
1469
|
|
|
filter_var( $x, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE ); |
1470
|
|
|
} |
1471
|
|
|
else { |
1472
|
|
|
filter_var_array( $x, FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1473
|
|
|
} |
1474
|
|
|
', |
1475
|
|
|
'url' => 'https://php.net/filter_var', |
1476
|
|
|
'arg' => '$x', |
1477
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'float\', FILTER_VALIDATE_FLOAT, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1478
|
|
|
'notes' => array( |
1479
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1480
|
|
|
), |
1481
|
|
|
), |
1482
|
|
|
'filter_combined_flt_null_sanitize' => array( |
1483
|
|
|
'title' => 'filter_var (…)', |
1484
|
|
|
'tooltip' => ' |
1485
|
|
|
if( ! is_array( $x ) ) { |
1486
|
|
|
filter_var( $x, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_NULL_ON_FAILURE ); |
1487
|
|
|
} |
1488
|
|
|
else { |
1489
|
|
|
filter_var_array( $x, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1490
|
|
|
} |
1491
|
|
|
', |
1492
|
|
|
'url' => 'https://php.net/filter_var', |
1493
|
|
|
'arg' => '$x', |
1494
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'float\', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1495
|
|
|
'notes' => array( |
1496
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1497
|
|
|
), |
1498
|
|
|
), |
1499
|
|
|
|
1500
|
|
|
|
1501
|
|
|
'filter_combined_flt_null_sanitize_allow_x3' => array( |
1502
|
|
|
'title' => 'filter_var (…)', |
1503
|
|
|
'tooltip' => ' |
1504
|
|
|
if( ! is_array( $x ) ) { |
1505
|
|
|
filter_var( $x, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_NULL_ON_FAILURE|FILTER_FLAG_ALLOW_FRACTION| FILTER_FLAG_ALLOW_THOUSAND|FILTER_FLAG_ALLOW_SCIENTIFIC ); |
1506
|
|
|
} |
1507
|
|
|
else { |
1508
|
|
|
filter_var_array( $x, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_NULL_ON_FAILURE|FILTER_FLAG_ALLOW_FRACTION| FILTER_FLAG_ALLOW_THOUSAND|FILTER_FLAG_ALLOW_SCIENTIFIC ); // = Simplified... see note |
1509
|
|
|
} |
1510
|
|
|
', |
1511
|
|
|
'url' => 'https://php.net/filter_var', |
1512
|
|
|
'arg' => '$x', |
1513
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'float\', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_NULL_ON_FAILURE|FILTER_FLAG_ALLOW_FRACTION|FILTER_FLAG_ALLOW_THOUSAND|FILTER_FLAG_ALLOW_SCIENTIFIC ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1514
|
|
|
'notes' => array( |
1515
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1516
|
|
|
), |
1517
|
|
|
), |
1518
|
|
|
|
1519
|
|
|
|
1520
|
|
|
// Integer filters. |
1521
|
|
|
'filter_var_int' => array( |
1522
|
|
|
'title' => 'filter_var (…)', |
1523
|
|
|
'tooltip' => 'filter_var( $x, FILTER_VALIDATE_INT )', |
1524
|
|
|
'url' => 'https://php.net/filter_var', |
1525
|
|
|
'arg' => '$x', |
1526
|
|
|
'function' => 'if ( function_exists( \'filter_var\' ) ) { $r = filter_var( $x, FILTER_VALIDATE_INT ); if ( is_int( $r ) ) { pr_int( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1527
|
|
|
), |
1528
|
|
|
'filter_var_array_int' => array( |
1529
|
|
|
'title' => 'filter_var_array (…)', |
1530
|
|
|
'tooltip' => 'filter_var_array( $x, FILTER_VALIDATE_INT )', |
1531
|
|
|
'url' => 'https://php.net/filter_var_array', |
1532
|
|
|
'arg' => '$x', |
1533
|
|
|
'function' => 'if ( function_exists( \'filter_var_array\' ) ) { pr_var( filter_var_array( $x, FILTER_VALIDATE_INT ), \'\', true, true ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1534
|
|
|
), |
1535
|
|
|
'filter_combined_int' => array( |
1536
|
|
|
'title' => 'filter_var (…)', |
1537
|
|
|
'tooltip' => ' |
1538
|
|
|
if( ! is_array( $x ) ) { |
1539
|
|
|
filter_var( $x, FILTER_VALIDATE_INT ); |
1540
|
|
|
} |
1541
|
|
|
else { |
1542
|
|
|
filter_var_array( $x, FILTER_VALIDATE_INT ); |
1543
|
|
|
} |
1544
|
|
|
', |
1545
|
|
|
'url' => 'https://php.net/filter_var', |
1546
|
|
|
'arg' => '$x', |
1547
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'int\', FILTER_VALIDATE_INT ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1548
|
|
|
), |
1549
|
|
|
'filter_combined_int_null' => array( |
1550
|
|
|
'title' => 'filter_var (…)', |
1551
|
|
|
'tooltip' => ' |
1552
|
|
|
if( ! is_array( $x ) ) { |
1553
|
|
|
filter_var( $x, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE ); |
1554
|
|
|
} |
1555
|
|
|
else { |
1556
|
|
|
filter_var_array( $x, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1557
|
|
|
} |
1558
|
|
|
', |
1559
|
|
|
'url' => 'https://php.net/filter_var', |
1560
|
|
|
'arg' => '$x', |
1561
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'int\', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1562
|
|
|
'notes' => array( |
1563
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1564
|
|
|
), |
1565
|
|
|
), |
1566
|
|
|
'filter_combined_int_null_min_max' => array( |
1567
|
|
|
'title' => 'filter_var (…)', |
1568
|
|
|
'tooltip' => ' |
1569
|
|
|
$options = array( \'min_range\' => 1, \'max_range\' => 50 ); |
1570
|
|
|
if( ! is_array( $x ) ) { |
1571
|
|
|
filter_var( $x, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE, $options ); |
1572
|
|
|
} |
1573
|
|
|
else { |
1574
|
|
|
filter_var_array( $x, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE, $options ); // = Simplified... see note |
1575
|
|
|
} |
1576
|
|
|
', |
1577
|
|
|
'url' => 'https://php.net/filter_var', |
1578
|
|
|
'arg' => '$x', |
1579
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { $options = array( \'min_range\' => 1, \'max_range\' => 50 ); VartypePHP5::filter_combined( $x, \'int\', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE, $options ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1580
|
|
|
'notes' => array( |
1581
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1582
|
|
|
), |
1583
|
|
|
), |
1584
|
|
|
|
1585
|
|
|
'filter_combined_int_null_hex_octal' => array( |
1586
|
|
|
'title' => 'filter_var (…)', |
1587
|
|
|
'tooltip' => ' |
1588
|
|
|
if( ! is_array( $x ) ) { |
1589
|
|
|
filter_var( $x, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE| FILTER_FLAG_ALLOW_HEX|FILTER_FLAG_ALLOW_OCTAL ); |
1590
|
|
|
} |
1591
|
|
|
else { |
1592
|
|
|
filter_var_array( $x, FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE| FILTER_FLAG_ALLOW_HEX|FILTER_FLAG_ALLOW_OCTAL ); // = Simplified... see note |
1593
|
|
|
} |
1594
|
|
|
', |
1595
|
|
|
'url' => 'https://php.net/filter_var', |
1596
|
|
|
'arg' => '$x', |
1597
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'int\', FILTER_VALIDATE_INT, FILTER_NULL_ON_FAILURE|FILTER_FLAG_ALLOW_HEX|FILTER_FLAG_ALLOW_OCTAL ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1598
|
|
|
'notes' => array( |
1599
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1600
|
|
|
), |
1601
|
|
|
), |
1602
|
|
|
|
1603
|
|
|
'filter_combined_int_null_sanitize' => array( |
1604
|
|
|
'title' => 'filter_var (…)', |
1605
|
|
|
'tooltip' => ' |
1606
|
|
|
if( ! is_array( $x ) ) { |
1607
|
|
|
filter_var( $x, FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE ); |
1608
|
|
|
} |
1609
|
|
|
else { |
1610
|
|
|
filter_var_array( $x, FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1611
|
|
|
} |
1612
|
|
|
', |
1613
|
|
|
'url' => 'https://php.net/filter_var', |
1614
|
|
|
'arg' => '$x', |
1615
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'int\', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1616
|
|
|
'notes' => array( |
1617
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1618
|
|
|
), |
1619
|
|
|
), |
1620
|
|
|
|
1621
|
|
|
'filter_combined_int_null_sanitize_x3' => array( |
1622
|
|
|
'title' => 'filter_var (…)', |
1623
|
|
|
'tooltip' => ' |
1624
|
|
|
if( ! is_array( $x ) ) { |
1625
|
|
|
filter_var( $x, FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE| FILTER_FLAG_ALLOW_HEX|FILTER_FLAG_ALLOW_OCTAL ); |
1626
|
|
|
} |
1627
|
|
|
else { |
1628
|
|
|
filter_var_array( $x, FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE| FILTER_FLAG_ALLOW_HEX|FILTER_FLAG_ALLOW_OCTAL ); // = Simplified... see note |
1629
|
|
|
} |
1630
|
|
|
', |
1631
|
|
|
'url' => 'https://php.net/filter_var', |
1632
|
|
|
'arg' => '$x', |
1633
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'int\', FILTER_SANITIZE_NUMBER_INT, FILTER_NULL_ON_FAILURE|FILTER_FLAG_ALLOW_HEX|FILTER_FLAG_ALLOW_OCTAL ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1634
|
|
|
'notes' => array( |
1635
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1636
|
|
|
), |
1637
|
|
|
), |
1638
|
|
|
|
1639
|
|
|
|
1640
|
|
|
|
1641
|
|
|
|
1642
|
|
|
// String filters. |
1643
|
|
|
'filter_var_string' => array( |
1644
|
|
|
'title' => 'filter_var (…)', |
1645
|
|
|
'tooltip' => 'filter_var( $x, FILTER_UNSAFE_RAW )', |
1646
|
|
|
'url' => 'https://php.net/filter_var', |
1647
|
|
|
'arg' => '$x', |
1648
|
|
|
'function' => 'if ( function_exists( \'filter_var\' ) ) { $r = filter_var( $x, FILTER_UNSAFE_RAW ); if ( is_string( $r ) ) { pr_str( $r ); } else { pr_var( $r, \'\', true, true ); } } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1649
|
|
|
), |
1650
|
|
|
'filter_var_array_string' => array( |
1651
|
|
|
'title' => 'filter_var_array (…)', |
1652
|
|
|
'tooltip' => 'filter_var_array( $x, FILTER_UNSAFE_RAW )', |
1653
|
|
|
'url' => 'https://php.net/filter_var_array', |
1654
|
|
|
'arg' => '$x', |
1655
|
|
|
'function' => 'if ( function_exists( \'filter_var_array\' ) ) { pr_var( filter_var_array( $x, FILTER_UNSAFE_RAW ), \'\', true, true ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1656
|
|
|
), |
1657
|
|
|
'filter_combined_string' => array( |
1658
|
|
|
'title' => 'filter_var (…)', |
1659
|
|
|
'tooltip' => ' |
1660
|
|
|
if( ! is_array( $x ) ) { |
1661
|
|
|
filter_var( $x, FILTER_UNSAFE_RAW ); |
1662
|
|
|
} |
1663
|
|
|
else { |
1664
|
|
|
filter_var_array( $x, FILTER_UNSAFE_RAW ); |
1665
|
|
|
} |
1666
|
|
|
', |
1667
|
|
|
'url' => 'https://php.net/filter_var', |
1668
|
|
|
'arg' => '$x', |
1669
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_UNSAFE_RAW ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1670
|
|
|
), |
1671
|
|
|
'filter_combined_string_null' => array( |
1672
|
|
|
'title' => 'filter_var (…)', |
1673
|
|
|
'tooltip' => ' |
1674
|
|
|
if( ! is_array( $x ) ) { |
1675
|
|
|
filter_var( $x, FILTER_UNSAFE_RAW, FILTER_NULL_ON_FAILURE ); |
1676
|
|
|
} |
1677
|
|
|
else { |
1678
|
|
|
filter_var_array( $x, FILTER_UNSAFE_RAW, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1679
|
|
|
} |
1680
|
|
|
', |
1681
|
|
|
'url' => 'https://php.net/filter_var', |
1682
|
|
|
'arg' => '$x', |
1683
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_UNSAFE_RAW, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1684
|
|
|
'notes' => array( |
1685
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1686
|
|
|
), |
1687
|
|
|
), |
1688
|
|
|
|
1689
|
|
|
|
1690
|
|
|
'filter_combined_str_null_sanitize' => array( |
1691
|
|
|
'title' => 'filter_var (…)', |
1692
|
|
|
'tooltip' => ' |
1693
|
|
|
if( ! is_array( $x ) ) { |
1694
|
|
|
filter_var( $x, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ); |
1695
|
|
|
} |
1696
|
|
|
else { |
1697
|
|
|
filter_var_array( $x, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1698
|
|
|
} |
1699
|
|
|
', |
1700
|
|
|
'url' => 'https://php.net/filter_var', |
1701
|
|
|
'arg' => '$x', |
1702
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1703
|
|
|
'notes' => array( |
1704
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1705
|
|
|
), |
1706
|
|
|
), |
1707
|
|
|
|
1708
|
|
|
|
1709
|
|
|
'filter_combined_str_null_sanitize_encode' => array( |
1710
|
|
|
'title' => 'filter_var (…)', |
1711
|
|
|
'tooltip' => ' |
1712
|
|
|
if( ! is_array( $x ) ) { |
1713
|
|
|
filter_var( $x, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE| FILTER_FLAG_ENCODE_LOW|FILTER_FLAG_ENCODE_HIGH|FILTER_FLAG_ENCODE_AMP ); |
1714
|
|
|
} |
1715
|
|
|
else { |
1716
|
|
|
filter_var_array( $x, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE| FILTER_FLAG_ENCODE_LOW|FILTER_FLAG_ENCODE_HIGH|FILTER_FLAG_ENCODE_AMP ); // = Simplified... see note |
1717
|
|
|
} |
1718
|
|
|
', |
1719
|
|
|
'url' => 'https://php.net/filter_var', |
1720
|
|
|
'arg' => '$x', |
1721
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE|FILTER_FLAG_ENCODE_LOW|FILTER_FLAG_ENCODE_HIGH|FILTER_FLAG_ENCODE_AMP ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1722
|
|
|
'notes' => array( |
1723
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1724
|
|
|
), |
1725
|
|
|
), |
1726
|
|
|
|
1727
|
|
|
'filter_combined_str_null_sanitize_strip' => array( |
1728
|
|
|
'title' => 'filter_var (…)', |
1729
|
|
|
'tooltip' => ' |
1730
|
|
|
if( ! is_array( $x ) ) { |
1731
|
|
|
filter_var( $x, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE| FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH ); |
1732
|
|
|
} |
1733
|
|
|
else { |
1734
|
|
|
filter_var_array( $x, FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE| FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH ); // = Simplified... see note |
1735
|
|
|
} |
1736
|
|
|
', |
1737
|
|
|
'url' => 'https://php.net/filter_var', |
1738
|
|
|
'arg' => '$x', |
1739
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE|FILTER_FLAG_STRIP_LOW|FILTER_FLAG_STRIP_HIGH ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1740
|
|
|
'notes' => array( |
1741
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1742
|
|
|
), |
1743
|
|
|
), |
1744
|
|
|
|
1745
|
|
|
'filter_combined_str_null_sanitize_special_chars' => array( |
1746
|
|
|
'title' => 'filter_var (…)', |
1747
|
|
|
'tooltip' => ' |
1748
|
|
|
if( ! is_array( $x ) ) { |
1749
|
|
|
filter_var( $x, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); |
1750
|
|
|
} |
1751
|
|
|
else { |
1752
|
|
|
filter_var_array( $x, FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1753
|
|
|
} |
1754
|
|
|
', |
1755
|
|
|
'url' => 'https://php.net/filter_var', |
1756
|
|
|
'arg' => '$x', |
1757
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_SANITIZE_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.2.0+)\n"; }', |
1758
|
|
|
'notes' => array( |
1759
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1760
|
|
|
), |
1761
|
|
|
), |
1762
|
|
|
|
1763
|
|
|
'filter_combined_str_null_sanitize_full_special_chars' => array( |
1764
|
|
|
'title' => 'filter_var (…)', |
1765
|
|
|
'tooltip' => ' |
1766
|
|
|
if( ! is_array( $x ) ) { |
1767
|
|
|
filter_var( $x, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); |
1768
|
|
|
} |
1769
|
|
|
else { |
1770
|
|
|
filter_var_array( $x, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); // = Simplified... see note |
1771
|
|
|
} |
1772
|
|
|
', |
1773
|
|
|
'url' => 'https://php.net/filter_var', |
1774
|
|
|
'arg' => '$x', |
1775
|
|
|
'function' => 'if ( extension_loaded( \'filter\' ) && defined( \'FILTER_SANITIZE_FULL_SPECIAL_CHARS\' ) ) { VartypePHP5::filter_combined( $x, \'string\', FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_NULL_ON_FAILURE ); } else { print "E: not available (PHP 5.3.3+)\n"; }', |
1776
|
|
|
'notes' => array( |
1777
|
|
|
'<p>The code snippet is simplified for brevity. Please refer to the source of this file on <a href="https://github.com/jrfnl/PHP-cheat-sheet-extended" target="_blank">GitHub</a> for full details on how to use filter_var_array().</p>', |
1778
|
|
|
), |
1779
|
|
|
), |
1780
|
|
|
|
1781
|
|
|
); |
1782
|
|
|
|
1783
|
|
|
|
1784
|
|
|
/** |
1785
|
|
|
* Setup the various tests across subsections to be show in individual tabs. |
1786
|
|
|
* |
1787
|
|
|
* @var array $test_groups |
1788
|
|
|
*/ |
1789
|
|
|
var $test_groups = array( |
1790
|
|
|
|
1791
|
|
|
'general' => array( |
1792
|
|
|
'title' => 'General typing', |
1793
|
|
|
'tests' => array( |
1794
|
|
|
'gettype', |
1795
|
|
|
'empty', |
1796
|
|
|
'is_null', |
1797
|
|
|
'isset', |
1798
|
|
|
'bool', |
1799
|
|
|
'if_var', |
1800
|
|
|
'null_coalesce', |
1801
|
|
|
), |
1802
|
|
|
'break_at' => array( 'gettype', 'if_var' ), |
1803
|
|
|
'good' => array(), |
1804
|
|
|
'best' => array(), |
1805
|
|
|
'urls' => array(), |
1806
|
|
|
'book_url' => 'https://php.net/types.comparisons', |
1807
|
|
|
'target' => null, |
1808
|
|
|
), |
1809
|
|
|
|
1810
|
|
|
'type_testing' => array( |
1811
|
|
|
'title' => 'is_…()', |
1812
|
|
|
'tests' => array( |
1813
|
|
|
'gettype', |
1814
|
|
|
|
1815
|
|
|
'is_null', |
1816
|
|
|
|
1817
|
|
|
'is_scalar', |
1818
|
|
|
'is_bool', |
1819
|
|
|
'is_int', |
1820
|
|
|
'is_float', |
1821
|
|
|
'is_string', |
1822
|
|
|
|
1823
|
|
|
'is_array', |
1824
|
|
|
'is_object', |
1825
|
|
|
'is_resource', |
1826
|
|
|
|
1827
|
|
|
// 'is_binary', // PHP6 ? |
1828
|
|
|
'is_callable', |
1829
|
|
|
|
1830
|
|
|
'is_numeric', |
1831
|
|
|
|
1832
|
|
|
'is_iterable', |
1833
|
|
|
'is_countable', |
1834
|
|
|
), |
1835
|
|
|
'break_at' => array( 'gettype', 'is_null', 'is_string', 'is_resource', 'is_callable', 'is_numeric', 'is_countable' ), |
1836
|
|
|
'good' => array(), |
1837
|
|
|
'best' => array(), |
1838
|
|
|
'urls' => array(), |
1839
|
|
|
'book_url' => 'https://php.net/ref.var', |
1840
|
|
|
'target' => null, |
1841
|
|
|
), |
1842
|
|
|
|
1843
|
|
|
|
1844
|
|
|
'null_tests' => array( |
1845
|
|
|
'title' => 'Null', |
1846
|
|
|
'tests' => array( |
1847
|
|
|
'settype_null', |
1848
|
|
|
'unset', |
1849
|
|
|
'f_unset', |
1850
|
|
|
'cast_to_type_null', |
1851
|
|
|
|
1852
|
|
|
'isset', |
1853
|
|
|
'null_coalesce', |
1854
|
|
|
'empty', |
1855
|
|
|
|
1856
|
|
|
'is_null', |
1857
|
|
|
'null_cmp_loose', |
1858
|
|
|
'null_cmp_strict', |
1859
|
|
|
'null_cmp_loose_str', |
1860
|
|
|
'null_cmp_strict_str', |
1861
|
|
|
), |
1862
|
|
|
'break_at' => array( 'cast_to_type_null', 'empty', 'null_cmp_strict_str', 'null_cmp_rv_strict_str' ), |
1863
|
|
|
'good' => array(), |
1864
|
|
|
'best' => array(), |
1865
|
|
|
'urls' => array(), |
1866
|
|
|
'book_url' => 'https://php.net/types.comparisons', |
1867
|
|
|
'target' => 'n', |
1868
|
|
|
), |
1869
|
|
|
|
1870
|
|
|
|
1871
|
|
|
'boolean_tests' => array( |
1872
|
|
|
'title' => 'Boolean', |
1873
|
|
|
'tests' => array( |
1874
|
|
|
'settype_bool', |
1875
|
|
|
'bool', |
1876
|
|
|
'filter_combined_bool', |
1877
|
|
|
'filter_combined_bool_null', |
1878
|
|
|
'cast_to_type_bool_not_empty_recurse_arrays', |
1879
|
|
|
|
1880
|
|
|
'is_bool', |
1881
|
|
|
|
1882
|
|
|
'bool_cmp_true_loose', |
1883
|
|
|
'bool_cmp_true_strict', |
1884
|
|
|
'bool_cmp_true_loose_int', |
1885
|
|
|
'bool_cmp_true_loose_str', |
1886
|
|
|
|
1887
|
|
|
'bool_cmp_false_loose', |
1888
|
|
|
'bool_cmp_false_strict', |
1889
|
|
|
'bool_cmp_false_loose_int', |
1890
|
|
|
'bool_cmp_false_loose_str', |
1891
|
|
|
|
1892
|
|
|
'if_var', |
1893
|
|
|
'if_not_var', |
1894
|
|
|
|
1895
|
|
|
), |
1896
|
|
|
'break_at' => array( 'cast_to_type_bool_not_empty_recurse_arrays', 'is_bool', 'bool_cmp_true_loose_str', 'bool_cmp_rv_true_strict_str', 'bool_cmp_false_loose_str', 'bool_cmp_rv_false_strict_str', 'if_not_var' ), |
1897
|
|
|
'good' => array(), |
1898
|
|
|
'best' => array(), |
1899
|
|
|
'urls' => array(), |
1900
|
|
|
'book_url' => 'https://php.net/types.comparisons', |
1901
|
|
|
'target' => 'b', |
1902
|
|
|
), |
1903
|
|
|
|
1904
|
|
|
|
1905
|
|
|
'integer_tests' => array( |
1906
|
|
|
'title' => 'Integers', |
1907
|
|
|
'tests' => array( |
1908
|
|
|
'settype_int', |
1909
|
|
|
'int', |
1910
|
|
|
'intval', |
1911
|
|
|
'juggle_int', |
1912
|
|
|
'filter_combined_int', |
1913
|
|
|
'filter_combined_int_null', |
1914
|
|
|
'cast_to_type_int_not_empty_recurse_arrays', |
1915
|
|
|
|
1916
|
|
|
'abs', |
1917
|
|
|
|
1918
|
|
|
'empty', |
1919
|
|
|
'is_int', |
1920
|
|
|
'is_numeric', |
1921
|
|
|
'ctype_digit', |
1922
|
|
|
'preg_int_pos', |
1923
|
|
|
'preg_int', |
1924
|
|
|
'preg_int_unicode', |
1925
|
|
|
), |
1926
|
|
|
'break_at' => array( 'cast_to_type_int_not_empty_recurse_arrays', 'abs', 'preg_int_unicode' ), |
1927
|
|
|
'good' => array(), |
1928
|
|
|
'best' => array(), |
1929
|
|
|
'urls' => array(), |
1930
|
|
|
'book_url' => 'https://php.net/book.var', |
1931
|
|
|
'target' => 'i', |
1932
|
|
|
), |
1933
|
|
|
|
1934
|
|
|
|
1935
|
|
|
'float_tests' => array( |
1936
|
|
|
'title' => 'Floats', |
1937
|
|
|
'tests' => array( |
1938
|
|
|
'settype_float', |
1939
|
|
|
'float', |
1940
|
|
|
'floatval', |
1941
|
|
|
'juggle_flt', |
1942
|
|
|
'filter_combined_float', |
1943
|
|
|
'filter_combined_float_null', |
1944
|
|
|
'cast_to_type_float_not_empty_recurse_arrays', |
1945
|
|
|
|
1946
|
|
|
'empty', |
1947
|
|
|
'is_float', |
1948
|
|
|
'is_numeric', |
1949
|
|
|
'ctype_digit', |
1950
|
|
|
'preg_float_pos', |
1951
|
|
|
'preg_float', |
1952
|
|
|
'preg_number_unicode', |
1953
|
|
|
), |
1954
|
|
|
'break_at' => array( 'cast_to_type_float_not_empty_recurse_arrays', 'preg_number_unicode' ), |
1955
|
|
|
'good' => array(), |
1956
|
|
|
'best' => array(), |
1957
|
|
|
'urls' => array(), |
1958
|
|
|
'book_url' => 'https://php.net/book.var', |
1959
|
|
|
'target' => 'f', |
1960
|
|
|
), |
1961
|
|
|
|
1962
|
|
|
|
1963
|
|
|
'numeric_tests' => array( |
1964
|
|
|
'title' => 'Numeric tests', |
1965
|
|
|
'tests' => array( |
1966
|
|
|
'is_numeric', |
1967
|
|
|
|
1968
|
|
|
'ctype_digit', |
1969
|
|
|
'preg_int_unicode', |
1970
|
|
|
'preg_number_unicode', |
1971
|
|
|
|
1972
|
|
|
'int_cmp_gt0', |
1973
|
|
|
'int_cmp_gte0', |
1974
|
|
|
'int_cmp_is0_loose', |
1975
|
|
|
'int_cmp_is0_strict', |
1976
|
|
|
'int_cmp_not0_loose', |
1977
|
|
|
'int_cmp_not0_strict', |
1978
|
|
|
'int_cmp_lt0', |
1979
|
|
|
'int_cmp_lte0', |
1980
|
|
|
|
1981
|
|
|
'is_nan', |
1982
|
|
|
'is_finite', |
1983
|
|
|
'is_infinite', |
1984
|
|
|
|
1985
|
|
|
'floor', |
1986
|
|
|
'ceil', |
1987
|
|
|
'round', |
1988
|
|
|
), |
1989
|
|
|
'break_at' => array( 'is_numeric', 'preg_number_unicode', 'int_cmp_lte0', 'is_infinite', 'round' ), |
1990
|
|
|
'good' => array(), |
1991
|
|
|
'best' => array(), |
1992
|
|
|
'urls' => array(), |
1993
|
|
|
'book_url' => 'https://php.net/book.var', |
1994
|
|
|
'target' => '', |
1995
|
|
|
), |
1996
|
|
|
|
1997
|
|
|
|
1998
|
|
|
'string_casting' => array( |
1999
|
|
|
'title' => 'String casting', |
2000
|
|
|
'tests' => array( |
2001
|
|
|
'settype_string', |
2002
|
|
|
'string', |
2003
|
|
|
'strval', |
2004
|
|
|
'juggle_str', |
2005
|
|
|
'filter_combined_string', |
2006
|
|
|
'filter_combined_string_null', |
2007
|
|
|
'cast_to_type_string_not_empty_recurse_arrays', |
2008
|
|
|
), |
2009
|
|
|
'break_at' => array( 'cast_to_type_string_not_empty_recurse_arrays' ), |
2010
|
|
|
'good' => array(), |
2011
|
|
|
'best' => array(), |
2012
|
|
|
'urls' => array(), |
2013
|
|
|
'book_url' => 'https://php.net/book.strings', |
2014
|
|
|
'target' => 's', |
2015
|
|
|
), |
2016
|
|
|
|
2017
|
|
|
|
2018
|
|
|
'string_tests' => array( |
2019
|
|
|
'title' => 'String tests', |
2020
|
|
|
'tests' => array( |
2021
|
|
|
'is_string', |
2022
|
|
|
|
2023
|
|
|
'empty', |
2024
|
|
|
'str_cmp_empty_loose', |
2025
|
|
|
'str_cmp_empty_strict', |
2026
|
|
|
|
2027
|
|
|
'ctype_alpha', |
2028
|
|
|
'preg_alpha', |
2029
|
|
|
'preg_alpha_unicode', |
2030
|
|
|
|
2031
|
|
|
'ctype_alnum', |
2032
|
|
|
'preg_alnum', |
2033
|
|
|
'preg_word', |
2034
|
|
|
'preg_word_utf8', |
2035
|
|
|
'preg_alnum_unicode', |
2036
|
|
|
|
2037
|
|
|
'strlen', |
2038
|
|
|
'count_chars', |
2039
|
|
|
'mb_strlen', |
2040
|
|
|
|
2041
|
|
|
'char_access', |
2042
|
|
|
|
2043
|
|
|
'trim', |
2044
|
|
|
), |
2045
|
|
|
'break_at' => array( 'is_string', 'str_cmp_empty_strict', 'preg_alpha_unicode', 'preg_alnum_unicode', 'mb_strlen', 'char_access', 'trim' ), |
2046
|
|
|
'good' => array(), |
2047
|
|
|
'best' => array(), |
2048
|
|
|
'urls' => array(), |
2049
|
|
|
'book_url' => 'https://php.net/book.strings', |
2050
|
|
|
'target' => 's', |
2051
|
|
|
), |
2052
|
|
|
|
2053
|
|
|
|
2054
|
|
|
'array_casting' => array( |
2055
|
|
|
'title' => 'Array casting', |
2056
|
|
|
'tests' => array( |
2057
|
|
|
'settype_array', |
2058
|
|
|
'array', |
2059
|
|
|
'cast_to_type_array_not_empty', |
2060
|
|
|
), |
2061
|
|
|
'break_at' => array( 'cast_to_type_array_not_empty' ), |
2062
|
|
|
'good' => array(), |
2063
|
|
|
'best' => array(), |
2064
|
|
|
'urls' => array(), |
2065
|
|
|
'book_url' => 'https://php.net/book.array', |
2066
|
|
|
'target' => 'a', |
2067
|
|
|
), |
2068
|
|
|
|
2069
|
|
|
|
2070
|
|
|
'array_tests' => array( |
2071
|
|
|
'title' => 'Array testing', |
2072
|
|
|
'tests' => array( |
2073
|
|
|
'is_array', |
2074
|
|
|
'count', |
2075
|
|
|
|
2076
|
|
|
'empty', |
2077
|
|
|
'count_mt_0', |
2078
|
|
|
'is_iterable', |
2079
|
|
|
'is_countable', |
2080
|
|
|
|
2081
|
|
|
'isset_0', |
2082
|
|
|
'array_key_exists', |
2083
|
|
|
'isset_foo', |
2084
|
|
|
|
2085
|
|
|
'key', |
2086
|
|
|
'current', |
2087
|
|
|
'array_access_simple_string', |
2088
|
|
|
'array_access_multi_string', |
2089
|
|
|
|
2090
|
|
|
'array_filter', |
2091
|
|
|
), |
2092
|
|
|
'break_at' => array( 'count', 'is_countable', 'isset_foo', 'array_access_multi_string', 'array_filter' ), |
2093
|
|
|
'good' => array(), |
2094
|
|
|
'best' => array(), |
2095
|
|
|
'urls' => array(), |
2096
|
|
|
'book_url' => 'https://php.net/book.array', |
2097
|
|
|
'target' => 'a', |
2098
|
|
|
), |
2099
|
|
|
|
2100
|
|
|
|
2101
|
|
|
'object_tests' => array( |
2102
|
|
|
'title' => 'Objects', |
2103
|
|
|
'tests' => array( |
2104
|
|
|
'settype_object', |
2105
|
|
|
'object', |
2106
|
|
|
'cast_to_type_object_not_empty', |
2107
|
|
|
|
2108
|
|
|
'is_object', |
2109
|
|
|
'is_a', |
2110
|
|
|
'instanceof', |
2111
|
|
|
|
2112
|
|
|
'get_class', |
2113
|
|
|
'get_parent_class', |
2114
|
|
|
'is_subclass_of', |
2115
|
|
|
), |
2116
|
|
|
'break_at' => array( 'cast_to_type_object', 'cast_to_type_object_not_empty', 'instanceof', 'is_subclass_of' ), |
2117
|
|
|
'good' => array(), |
2118
|
|
|
'best' => array(), |
2119
|
|
|
'urls' => array(), |
2120
|
|
|
'book_url' => 'https://php.net/book.classobj', |
2121
|
|
|
'target' => 'o', |
2122
|
|
|
), |
2123
|
|
|
|
2124
|
|
|
|
2125
|
|
|
'resource_tests' => array( |
2126
|
|
|
'title' => 'Resources', |
2127
|
|
|
'tests' => array( |
2128
|
|
|
'is_resource', |
2129
|
|
|
'get_resource_type', |
2130
|
|
|
), |
2131
|
|
|
'break_at' => array( 'is_resource', 'get_resource_type' ), |
2132
|
|
|
'good' => array(), |
2133
|
|
|
'best' => array(), |
2134
|
|
|
'urls' => array(), |
2135
|
|
|
'book_url' => '', |
2136
|
|
|
'target' => 'r', |
2137
|
|
|
), |
2138
|
|
|
|
2139
|
|
|
|
2140
|
|
|
'arithmetic' => array( |
2141
|
|
|
'title' => 'Basic Arithmetic', |
2142
|
|
|
'tests' => array( |
2143
|
|
|
'pre_increment', |
2144
|
|
|
'post_increment', |
2145
|
|
|
'pre_decrement', |
2146
|
|
|
'post_decrement', |
2147
|
|
|
|
2148
|
|
|
'arithmetic_negate', |
2149
|
|
|
'juggle_int', |
2150
|
|
|
'arithmetic_subtract', |
2151
|
|
|
'arithmetic_multiply', |
2152
|
|
|
'arithmetic_divide', |
2153
|
|
|
'arithmetic_modulus', |
2154
|
|
|
|
2155
|
|
|
), |
2156
|
|
|
'break_at' => array( 'post_decrement', 'arithmetic_modulus' ), |
2157
|
|
|
'good' => array(), |
2158
|
|
|
'best' => array(), |
2159
|
|
|
'urls' => array(), |
2160
|
|
|
'book_url' => 'https://php.net/language.operators.arithmetic', |
2161
|
|
|
'target' => '', |
2162
|
|
|
), |
2163
|
|
|
); |
2164
|
|
|
|
2165
|
|
|
|
2166
|
|
|
/** |
2167
|
|
|
* Additional testgroup only to be added if the ctype extension is available. |
2168
|
|
|
* |
2169
|
|
|
* @var array $ctype_test_group |
2170
|
|
|
*/ |
2171
|
|
|
var $ctype_test_group = array( |
2172
|
|
|
'ctype_extension' => array( |
2173
|
|
|
'title' => 'CType Extension', |
2174
|
|
|
'tests' => array( |
2175
|
|
|
'ctype_digit', |
2176
|
|
|
'ctype_xdigit', |
2177
|
|
|
|
2178
|
|
|
'ctype_alpha', |
2179
|
|
|
'ctype_alnum', |
2180
|
|
|
'ctype_graph', |
2181
|
|
|
'ctype_print', |
2182
|
|
|
|
2183
|
|
|
'ctype_lower', // Has issues on PHP 5.0.5. |
2184
|
|
|
'ctype_upper', |
2185
|
|
|
|
2186
|
|
|
'ctype_cntrl', // Has issues on PHP 5.0.5. |
2187
|
|
|
'ctype_punct', // Has issues on PHP 5.0.5. |
2188
|
|
|
'ctype_space', |
2189
|
|
|
), |
2190
|
|
|
'break_at' => array( 'ctype_xdigit', 'ctype_print', 'ctype_upper', 'ctype_space' ), |
2191
|
|
|
'good' => array(), |
2192
|
|
|
'best' => array(), |
2193
|
|
|
'urls' => array(), |
2194
|
|
|
'book_url' => 'https://php.net/book.ctype', |
2195
|
|
|
'target' => 's', |
2196
|
|
|
), |
2197
|
|
|
); |
2198
|
|
|
|
2199
|
|
|
|
2200
|
|
|
/** |
2201
|
|
|
* Additional testgroup only to be added if the filter extension is available. |
2202
|
|
|
* |
2203
|
|
|
* @var array $ctype_test_group |
2204
|
|
|
*/ |
2205
|
|
|
var $filter_test_group = array( |
2206
|
|
|
'filter_extension_bool_int_float' => array( |
2207
|
|
|
'title' => 'Filter Extension - bool/int/float', |
2208
|
|
|
'tests' => array( |
2209
|
|
|
'filter_combined_bool_null', |
2210
|
|
|
|
2211
|
|
|
'filter_combined_int_null', |
2212
|
|
|
'filter_combined_int_null_min_max', |
2213
|
|
|
'filter_combined_int_null_hex_octal', |
2214
|
|
|
'filter_combined_int_null_sanitize', |
2215
|
|
|
/* 'filter_combined_int_null_sanitize_x3', */ |
2216
|
|
|
|
2217
|
|
|
'filter_combined_float_null', |
2218
|
|
|
'filter_combined_flt_null_sanitize', |
2219
|
|
|
'filter_combined_flt_null_sanitize_allow_x3', |
2220
|
|
|
|
2221
|
|
|
), |
2222
|
|
|
'break_at' => array( 'filter_combined_bool_null', 'filter_combined_int_null_sanitize', 'filter_combined_flt_null_sanitize_allow_x3' ), |
2223
|
|
|
'good' => array(), |
2224
|
|
|
'best' => array(), |
2225
|
|
|
'urls' => array(), |
2226
|
|
|
'book_url' => 'https://php.net/book.filter', |
2227
|
|
|
'target' => '', |
2228
|
|
|
), |
2229
|
|
|
|
2230
|
|
|
'filter_extension_strings' => array( |
2231
|
|
|
'title' => 'Filter Extension - string', |
2232
|
|
|
'tests' => array( |
2233
|
|
|
'filter_combined_string_null', |
2234
|
|
|
'filter_combined_str_null_sanitize', |
2235
|
|
|
'filter_combined_str_null_sanitize_encode', |
2236
|
|
|
'filter_combined_str_null_sanitize_strip', |
2237
|
|
|
'filter_combined_str_null_sanitize_special_chars', |
2238
|
|
|
'filter_combined_str_null_sanitize_full_special_chars', |
2239
|
|
|
), |
2240
|
|
|
'break_at' => array( 'filter_combined_str_null_sanitize_full_special_chars' ), |
2241
|
|
|
'good' => array(), |
2242
|
|
|
'best' => array(), |
2243
|
|
|
'urls' => array(), |
2244
|
|
|
'book_url' => 'https://php.net/book.filter', |
2245
|
|
|
'target' => '', |
2246
|
|
|
), |
2247
|
|
|
); |
2248
|
|
|
|
2249
|
|
|
|
2250
|
|
|
/** |
2251
|
|
|
* Constructor. |
2252
|
|
|
*/ |
2253
|
|
|
function __construct() { |
2254
|
|
|
|
2255
|
|
|
// Make sure the tests presented will be compatible with the install the cheatsheet is running on. |
2256
|
|
|
$this->phpcompat_filter_tests(); |
2257
|
|
|
|
2258
|
|
|
/** |
2259
|
|
|
* Adjust float regex tests to use the correct decimal point character. |
2260
|
|
|
*/ |
2261
|
|
|
// Try & get decimal point for use in float operations. |
2262
|
|
|
if ( ! defined( 'DECIMAL_POINT' ) ) { |
2263
|
|
|
$locale_info = localeconv(); |
2264
|
|
|
define( 'DECIMAL_POINT', $locale_info['decimal_point'] ); |
2265
|
|
|
unset( $locale_info ); |
2266
|
|
|
} |
2267
|
|
|
// Prep decimal point for use in regex. |
2268
|
|
|
if ( defined( 'DECIMAL_POINT' ) ) { |
2269
|
|
|
$preg_point = preg_quote( DECIMAL_POINT, '`' ); |
2270
|
|
|
} |
2271
|
|
|
else { |
2272
|
|
|
$preg_point = preg_quote( '.,', '`' ); |
2273
|
|
|
} |
2274
|
|
|
|
2275
|
|
|
$targets = array( |
2276
|
|
|
'preg_float_pos', |
2277
|
|
|
'preg_float', |
2278
|
|
|
'preg_digit_float_pos', |
2279
|
|
|
'preg_digit_float', |
2280
|
|
|
'preg_number_unicode_pos', |
2281
|
|
|
'preg_number_unicode', |
2282
|
|
|
); |
2283
|
|
|
foreach ( $targets as $target ) { |
2284
|
|
|
foreach ( $this->tests[ $target ] as $key => $value ) { |
2285
|
|
|
$this->tests[ $target ][ $key ] = str_replace( '##PREG_DECIMAL_POINT##', $preg_point, $value ); |
2286
|
|
|
} |
2287
|
|
|
} |
2288
|
|
|
unset( $preg_point ); |
2289
|
|
|
|
2290
|
|
|
parent::__construct(); |
2291
|
|
|
} |
2292
|
|
|
|
2293
|
|
|
|
2294
|
|
|
/** |
2295
|
|
|
* PHP4 compatibility constructor. |
2296
|
|
|
*/ |
2297
|
|
|
function VartypeTest() { |
2298
|
|
|
$this->__construct(); |
2299
|
|
|
} |
2300
|
|
|
|
2301
|
|
|
|
2302
|
|
|
/** |
2303
|
|
|
* Filter out some tests which would break the cheatsheets and merge some which won't. |
2304
|
|
|
*/ |
2305
|
|
|
function phpcompat_filter_tests() { |
2306
|
|
|
|
2307
|
|
|
// Work around some bugs in PHP versions having issues with ctype. |
2308
|
|
|
if ( extension_loaded( 'ctype' ) ) { |
2309
|
|
|
// Remove some tests which give issues in PHP5.0.x. |
2310
|
|
|
if ( PHP_VERSION_ID === 50005 || PHP_VERSION_ID === 50004 ) { |
2311
|
|
|
unset( |
2312
|
|
|
$this->ctype_test_group['ctype_extension']['tests'][6], // Function ctype_lower(). |
2313
|
|
|
$this->ctype_test_group['ctype_extension']['tests'][8], // Function ctype_cntrl(). |
2314
|
|
|
$this->ctype_test_group['ctype_extension']['tests'][9] // Function ctype_punct(). |
2315
|
|
|
); |
2316
|
|
|
} |
2317
|
|
|
// Merge the ctype testgroup. |
2318
|
|
|
$this->test_groups = array_merge( $this->test_groups, $this->ctype_test_group ); |
2319
|
|
|
} |
2320
|
|
|
|
2321
|
|
|
if ( extension_loaded( 'filter' ) && function_exists( 'filter_var' ) && defined( 'FILTER_NULL_ON_FAILURE' ) ) { |
2322
|
|
|
$this->test_groups = array_merge( $this->test_groups, $this->filter_test_group ); |
2323
|
|
|
} |
2324
|
|
|
|
2325
|
|
|
// Remove null coalesce test for PHP < 7. |
2326
|
|
|
if ( PHP_VERSION_ID < 70000 ) { |
2327
|
|
|
unset( |
2328
|
|
|
$this->tests['null_coalesce'], |
2329
|
|
|
$this->test_groups['general']['tests'][6], |
2330
|
|
|
$this->test_groups['null_tests']['tests'][5] |
2331
|
|
|
); |
2332
|
|
|
} |
2333
|
|
|
} |
2334
|
|
|
|
2335
|
|
|
|
2336
|
|
|
/** |
2337
|
|
|
* Work around some really weird bug which I haven't been able to track down yet. |
2338
|
|
|
* |
2339
|
|
|
* Bug details: some semi-random text string is shown for the INF constant on the |
2340
|
|
|
* object_test sheet in PHP 5.0.x. |
2341
|
|
|
* Similarly a "Fatal error: Unknown function: f8()" is shown just before the array_testing group in 4.3.11. |
2342
|
|
|
* |
2343
|
|
|
* @param string|null $test_group The current subsection. |
2344
|
|
|
*/ |
2345
|
|
|
function set_test_data( $test_group = null ) { |
2346
|
|
|
parent::set_test_data( $test_group ); |
2347
|
|
|
|
2348
|
|
|
if ( ( PHP_VERSION_ID >= 50004 && PHP_VERSION_ID <= 50005 ) || phpversion() === '4.3.11' ) { |
2349
|
|
|
$key = array_search( 'f8', $this->test_data_keys, true ); |
2350
|
|
|
unset( $this->test_data_keys[ $key ], $this->test_data['f8'] ); |
2351
|
|
|
} |
2352
|
|
|
} |
2353
|
|
|
} |
2354
|
|
|
|