Annotation of embedaddon/php/ext/standard/tests/general_functions/is_numeric.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test is_numeric() function
3: --FILE--
4: <?php
5: /* Prototype: bool is_numeric ( mixed $var );
6: * Description: Finds whether a variable is a number or a numeric string
7: */
8:
9: echo "*** Testing is_numeric() with valid numeric values ***\n";
10: // different valid numeric vlaues
11: $numerics = array(
12: 0,
13: 1,
14: -1,
15: -0,
16: +0,
17: 0.0,
18: -0.0,
19: +0.0,
20: 1.0,
21: -1.0,
22: +1.0,
23: .5,
24: -.5,
25: +.5,
26: -.5e-2,
27: .5e-2,
28: +.5e-2,
29: +.5E+2,
30: 0.70000000,
31: +0.70000000,
32: -0.70000000,
33: 1234567890123456,
34: -1234567890123456,
35: 984847472827282718178,
36: -984847472827282718178,
37: 123.56e30,
38: 123.56E30,
39: 426.45e-30,
40: 5657.3E-40,
41: 3486.36e+40,
42: 3486.36E+90,
43: -3486.36E+10,
44: -3486.36e+80,
45: -426.45e-50,
46: -426.45E-99,
47: 1e2,
48: -1e2,
49: -1e-2,
50: +1e2,
51: +1e+2,
52: +1e-2,
53: +1e+2,
54: 2245555555555555.444,
55: 1.444444444444444444,
56: 0xff, // hexa decimal numbers
57: 0xFF,
58: //0x1111111111111111111111,
59: -0x1111111,
60: +0x6698319,
61: 01000000000000000000000,
62: 0123,
63: 0345900,
64: -0200001,
65: -0200001.7,
66: 0200001.7,
67: +0200001,
68: +0200001.7,
69: +0200001.7,
70: 2.00000000000000000000001, // a float value with more precision points
71: "1", // numeric in the form of string
72: "-1",
73: "1e2",
74: " 1",
75: "2974394749328742328432",
76: "-1e-2",
77: '1',
78: '-1',
79: '1e2',
80: ' 1',
81: '2974394749328742328432',
82: '-1e-2',
83: "0xff",
84: '0xff',
85: "0123",
86: '0123',
87: "-0123",
88: "+0123",
89: '-0123',
90: '+0123'
91: );
92: /* loop to check that is_numeric() recognizes different
93: numeric values, expected output: bool(true) */
94: $loop_counter = 1;
95: foreach ($numerics as $num ) {
96: echo "-- Iteration $loop_counter --\n"; $loop_counter++;
97: var_dump( is_numeric($num) );
98: }
99:
100: echo "\n*** Testing is_numeric() on non numeric types ***\n";
101:
102: // get a resource type variable
103: $fp = fopen (__FILE__, "r");
104: $dfp = opendir ( dirname(__FILE__) );
105:
106: // unset variable
107: $unset_var = 10.5;
108: unset ($unset_var);
109:
110: // other types in a array
111: $not_numerics = array(
112: "-0x80001",
113: "+0x80001",
114: "-0x80001.5",
115: "0x80001.5",
116: new stdclass, // object
117: $fp, // resource
118: $dfp,
119: array(),
120: array("string"),
121: "",
122: "1 ",
123: "- 1",
124: "1.2.4",
125: "1e7.6",
126: "3FF",
127: "20 test",
128: "3.6test",
129: "1,000",
130: "NULL",
131: "true",
132: true,
133: NULL,
134: null,
135: TRUE,
136: FALSE,
137: false,
138: @$unset_var, // unset variable
139: @$undefined_var
140: );
141: /* loop through the $not_numerics to see working of
142: is_numeric() on non numeric values, expected output: bool(false) */
143: $loop_counter = 1;
144: foreach ($not_numerics as $type ) {
145: echo "-- Iteration $loop_counter --\n"; $loop_counter++;
146: var_dump( is_numeric($type) );
147: }
148:
149: echo "\n*** Testing error conditions ***\n";
150: //Zero argument
151: var_dump( is_numeric() );
152:
153: //arguments more than expected
154: var_dump( is_numeric("10", "20") );
155:
156: echo "Done\n";
157:
158: // close the resources used
159: fclose($fp);
160: closedir($dfp);
161:
162: ?>
163: --EXPECTF--
164: *** Testing is_numeric() with valid numeric values ***
165: -- Iteration 1 --
166: bool(true)
167: -- Iteration 2 --
168: bool(true)
169: -- Iteration 3 --
170: bool(true)
171: -- Iteration 4 --
172: bool(true)
173: -- Iteration 5 --
174: bool(true)
175: -- Iteration 6 --
176: bool(true)
177: -- Iteration 7 --
178: bool(true)
179: -- Iteration 8 --
180: bool(true)
181: -- Iteration 9 --
182: bool(true)
183: -- Iteration 10 --
184: bool(true)
185: -- Iteration 11 --
186: bool(true)
187: -- Iteration 12 --
188: bool(true)
189: -- Iteration 13 --
190: bool(true)
191: -- Iteration 14 --
192: bool(true)
193: -- Iteration 15 --
194: bool(true)
195: -- Iteration 16 --
196: bool(true)
197: -- Iteration 17 --
198: bool(true)
199: -- Iteration 18 --
200: bool(true)
201: -- Iteration 19 --
202: bool(true)
203: -- Iteration 20 --
204: bool(true)
205: -- Iteration 21 --
206: bool(true)
207: -- Iteration 22 --
208: bool(true)
209: -- Iteration 23 --
210: bool(true)
211: -- Iteration 24 --
212: bool(true)
213: -- Iteration 25 --
214: bool(true)
215: -- Iteration 26 --
216: bool(true)
217: -- Iteration 27 --
218: bool(true)
219: -- Iteration 28 --
220: bool(true)
221: -- Iteration 29 --
222: bool(true)
223: -- Iteration 30 --
224: bool(true)
225: -- Iteration 31 --
226: bool(true)
227: -- Iteration 32 --
228: bool(true)
229: -- Iteration 33 --
230: bool(true)
231: -- Iteration 34 --
232: bool(true)
233: -- Iteration 35 --
234: bool(true)
235: -- Iteration 36 --
236: bool(true)
237: -- Iteration 37 --
238: bool(true)
239: -- Iteration 38 --
240: bool(true)
241: -- Iteration 39 --
242: bool(true)
243: -- Iteration 40 --
244: bool(true)
245: -- Iteration 41 --
246: bool(true)
247: -- Iteration 42 --
248: bool(true)
249: -- Iteration 43 --
250: bool(true)
251: -- Iteration 44 --
252: bool(true)
253: -- Iteration 45 --
254: bool(true)
255: -- Iteration 46 --
256: bool(true)
257: -- Iteration 47 --
258: bool(true)
259: -- Iteration 48 --
260: bool(true)
261: -- Iteration 49 --
262: bool(true)
263: -- Iteration 50 --
264: bool(true)
265: -- Iteration 51 --
266: bool(true)
267: -- Iteration 52 --
268: bool(true)
269: -- Iteration 53 --
270: bool(true)
271: -- Iteration 54 --
272: bool(true)
273: -- Iteration 55 --
274: bool(true)
275: -- Iteration 56 --
276: bool(true)
277: -- Iteration 57 --
278: bool(true)
279: -- Iteration 58 --
280: bool(true)
281: -- Iteration 59 --
282: bool(true)
283: -- Iteration 60 --
284: bool(true)
285: -- Iteration 61 --
286: bool(true)
287: -- Iteration 62 --
288: bool(true)
289: -- Iteration 63 --
290: bool(true)
291: -- Iteration 64 --
292: bool(true)
293: -- Iteration 65 --
294: bool(true)
295: -- Iteration 66 --
296: bool(true)
297: -- Iteration 67 --
298: bool(true)
299: -- Iteration 68 --
300: bool(true)
301: -- Iteration 69 --
302: bool(true)
303: -- Iteration 70 --
304: bool(true)
305: -- Iteration 71 --
306: bool(true)
307: -- Iteration 72 --
308: bool(true)
309: -- Iteration 73 --
310: bool(true)
311: -- Iteration 74 --
312: bool(true)
313: -- Iteration 75 --
314: bool(true)
315: -- Iteration 76 --
316: bool(true)
317: -- Iteration 77 --
318: bool(true)
319: -- Iteration 78 --
320: bool(true)
321:
322: *** Testing is_numeric() on non numeric types ***
323: -- Iteration 1 --
324: bool(false)
325: -- Iteration 2 --
326: bool(false)
327: -- Iteration 3 --
328: bool(false)
329: -- Iteration 4 --
330: bool(false)
331: -- Iteration 5 --
332: bool(false)
333: -- Iteration 6 --
334: bool(false)
335: -- Iteration 7 --
336: bool(false)
337: -- Iteration 8 --
338: bool(false)
339: -- Iteration 9 --
340: bool(false)
341: -- Iteration 10 --
342: bool(false)
343: -- Iteration 11 --
344: bool(false)
345: -- Iteration 12 --
346: bool(false)
347: -- Iteration 13 --
348: bool(false)
349: -- Iteration 14 --
350: bool(false)
351: -- Iteration 15 --
352: bool(false)
353: -- Iteration 16 --
354: bool(false)
355: -- Iteration 17 --
356: bool(false)
357: -- Iteration 18 --
358: bool(false)
359: -- Iteration 19 --
360: bool(false)
361: -- Iteration 20 --
362: bool(false)
363: -- Iteration 21 --
364: bool(false)
365: -- Iteration 22 --
366: bool(false)
367: -- Iteration 23 --
368: bool(false)
369: -- Iteration 24 --
370: bool(false)
371: -- Iteration 25 --
372: bool(false)
373: -- Iteration 26 --
374: bool(false)
375: -- Iteration 27 --
376: bool(false)
377: -- Iteration 28 --
378: bool(false)
379:
380: *** Testing error conditions ***
381:
382: Warning: is_numeric() expects exactly 1 parameter, 0 given in %s on line %d
383: NULL
384:
385: Warning: is_numeric() expects exactly 1 parameter, 2 given in %s on line %d
386: NULL
387: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>