Annotation of embedaddon/php/ext/standard/tests/general_functions/var_dump_64bit.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test var_dump() function
3: --SKIPIF--
4: <?php
5: if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
6: ?>
7: --INI--
8: precision=14
9: --FILE--
10: <?php
11: /* Prototype: void var_dump ( mixed $expression [, mixed $expression [, $...]] );
12: Description: Displays structured information about one or more expressions that includes its type and value.
13: */
14:
15: /* Prototype: void check_vardump( $variables );
16: Description: use var_dump() to display the variables */
17: function check_vardump( $variables ) {
18: $counter = 1;
19: foreach( $variables as $variable ) {
20: echo "-- Iteration $counter --\n";
21: var_dump($variable);
22: $counter++;
23: }
24: }
25:
26: echo "\n*** Testing var_dump() on integer variables ***\n";
27: $integers = array (
28: 0, // zero as argument
29: 000000123, //octal value of 83
30: 123000000,
31: -00000123, //octal value of 83
32: -12300000,
33: range(1,10), // positive values
34: range(-1,-10), // negative values
35: +2147483647, // max positive integer
36: +2147483648, // max positive integer + 1
37: -2147483648, // min range of integer
38: -2147483647, // min range of integer + 1
39: 0x7FFFFFFF, // max positive hexadecimal integer
40: -0x80000000, // min range of hexadecimal integer
41: 017777777777, // max posotive octal integer
42: -020000000000 // min range of octal integer
43: );
44: /* calling check_vardump() to display contents of integer variables
45: using var_dump() */
46: check_vardump($integers);
47:
48: echo "\n*** Testing var_dump() on float variables ***\n";
49: $floats = array (
50: -0.0,
51: +0.0,
52: 1.234,
53: -1.234,
54: -2.000000,
55: 000002.00,
56: -.5,
57: .567,
58: -.6700000e-3,
59: -.6700000E+3,
60: .6700000E+3,
61: .6700000e+3,
62: -4.10003e-3,
63: -4.10003E+3,
64: 4.100003e-3,
65: 4.100003E+3,
66: 1e5,
67: -1e5,
68: 1e-5,
69: -1e-5,
70: 1e+5,
71: -1e+5,
72: 1E5,
73: -1E5,
74: 1E+5,
75: -1E+5,
76: 1E-5,
77: -1E-5,
78: -0x80000001, // float value, beyond max negative int
79: 0x80000001, // float value, beyond max positive int
80: 020000000001, // float value, beyond max positive int
81: -020000000001 // float value, beyond max negative int
82: );
83: /* calling check_vardump() to display contents of float variables
84: using var_dump() */
85: check_vardump($floats);
86:
87: echo "\n*** Testing var_dump() on string variables ***\n";
88: $strings = array (
89: "",
90: '',
91: " ",
92: ' ',
93: "0",
94: "\0",
95: '\0',
96: "\t",
97: '\t',
98: "PHP",
99: 'PHP',
100: "abcd\x0n1234\x0005678\x0000efgh\xijkl", // strings with hexadecimal NULL
101: "abcd\0efgh\0ijkl\x00mnop\x000qrst\00uvwx\0000yz", // strings with octal NULL
102: "1234\t\n5678\n\t9100\rabcda" // strings with escape characters
103: );
104: /* calling check_vardump() to display contents of strings
105: using var_dump() */
106: check_vardump($strings);
107:
108: echo "\n*** Testing var_dump() on boolean variables ***\n";
109: $booleans = array (
110: TRUE,
111: FALSE,
112: true,
113: false
114: );
115: /* calling check_vardump() to display boolean variables
116: using var_dump() */
117: check_vardump($booleans);
118:
119: echo "\n*** Testing var_dump() on array variables ***\n";
120: $arrays = array (
121: array(),
122: array(NULL),
123: array(null),
124: array(true),
125: array(""),
126: array(''),
127: array(array(), array()),
128: array(array(1, 2), array('a', 'b')),
129: array(1 => 'One'),
130: array("test" => "is_array"),
131: array(0),
132: array(-1),
133: array(10.5, 5.6),
134: array("string", "test"),
135: array('string', 'test'),
136: );
137: /* calling check_vardump() to display contents of an array
138: using var_dump() */
139: check_vardump($arrays);
140:
141: echo "\n*** Testing var_dump() on object variables ***\n";
142: class object_class
143: {
144: var $value;
145: public $public_var1 = 10;
146: private $private_var1 = 20;
147: private $private_var2;
148: protected $protected_var1 = "string_1";
149: protected $protected_var2;
150:
151: function object_class ( ) {
152: $this->value = 50;
153: $this->public_var2 = 11;
154: $this->private_var2 = 21;
155: $this->protected_var2 = "string_2";
156: }
157:
158: public function foo1() {
159: echo "foo1() is called\n";
160: }
161: protected function foo2() {
162: echo "foo2() is called\n";
163: }
164: private function foo3() {
165: echo "foo3() is called\n";
166: }
167: }
168: /* class with no member */
169: class no_member_class {
170: // no members
171: }
172:
173: /* class with member as object of other class */
174: class contains_object_class
175: {
176: var $p = 30;
177: var $class_object1;
178: public $class_object2;
179: private $class_object3;
180: protected $class_object4;
181: var $no_member_class_object;
182:
183: public function func() {
184: echo "func() is called \n";
185: }
186:
187: function contains_object_class () {
188: $this->class_object1 = new object_class();
189: $this->class_object2 = new object_class();
190: $this->class_object3 = $this->class_object1;
191: $this->class_object4 = $this->class_object2;
192: $this->no_member_class_object = new no_member_class();
193: $this->class_object5 = $this; //recursive reference
194: }
195: }
196:
197: /* objects of different classes */
198: $obj = new contains_object_class;
199: $temp_class_obj = new object_class();
200:
201: /* object which is unset */
202: $unset_obj = new object_class();
203: unset($unset_obj);
204:
205: $objects = array (
206: new object_class,
207: new no_member_class,
208: new contains_object_class,
209: $obj,
210: $obj->class_object1,
211: $obj->class_object2,
212: $obj->no_member_class_object,
213: $temp_class_obj,
214: @$unset_obj
215: );
216: /* calling check_vardump() to display contents of the objects
217: using var_dump() */
218: check_vardump($objects);
219:
220: echo "\n** Testing var_dump() on objects having circular reference **\n";
221: $recursion_obj1 = new object_class();
222: $recursion_obj2 = new object_class();
223: $recursion_obj1->obj = &$recursion_obj2; //circular reference
224: $recursion_obj2->obj = &$recursion_obj1; //circular reference
225: var_dump($recursion_obj2);
226:
227: echo "\n*** Testing var_dump() on resources ***\n";
228: /* file type resource */
229: $file_handle = fopen(__FILE__, "r");
230:
231: /* directory type resource */
232: $dir_handle = opendir( dirname(__FILE__) );
233:
234: $resources = array (
235: $file_handle,
236: $dir_handle
237: );
238: /* calling check_vardump() to display the resource content type
239: using var_dump() */
240: check_vardump($resources);
241:
242: echo "\n*** Testing var_dump() on different combinations of scalar
243: and non-scalar variables ***\n";
244: /* a variable which is unset */
245: $unset_var = 10.5;
246: unset($unset_var);
247:
248: /* unset file type resource */
249: unset($file_handle);
250:
251: $variations = array (
252: array( 123, -1.2345, "a" ),
253: array( "d", array(1, 3, 5), true, null),
254: array( new no_member_class, array(), false, 0 ),
255: array( -0.00, "Where am I?", array(7,8,9), TRUE, 'A', 987654321 ),
256: array( @$unset_var, 2.E+10, 100-20.9, 000004.599998 ), //unusual data
257: array( "array(1,2,3,4)1.0000002TRUE", @$file_handle, 111333.00+45e5, '/00\7')
258: );
259: /* calling check_vardump() to display combinations of scalar and
260: non-scalar variables using var_dump() */
261: check_vardump($variations);
262:
263: echo "\n*** Testing var_dump() on miscelleneous input arguments ***\n";
264: $misc_values = array (
265: @$unset_var,
266: NULL, // NULL argument
267: @$undef_variable, //undefined variable
268: null
269: );
270: /* calling check_vardump() to display miscelleneous data using var_dump() */
271: check_vardump($misc_values);
272:
273: echo "\n*** Testing var_dump() on multiple arguments ***\n";
274: var_dump( $integers, $floats, $strings, $arrays, $booleans, $resources,
275: $objects, $misc_values, $variations );
276:
277: /* checking var_dump() on functions */
278: echo "\n*** Testing var_dump() on anonymous functions ***\n";
279: $newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
280: echo "New anonymous function: $newfunc\n";
281: var_dump( $newfunc(2, 3) );
282: /* creating anonymous function dynamically */
283: var_dump( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
284:
285: echo "\n*** Testing error conditions ***\n";
286: //passing zero argument
287: var_dump();
288:
289: /* closing resource handle used */
290: closedir($dir_handle);
291:
292: echo "Done\n";
293: ?>
294: --EXPECTF--
295: *** Testing var_dump() on integer variables ***
296: -- Iteration 1 --
297: int(0)
298: -- Iteration 2 --
299: int(83)
300: -- Iteration 3 --
301: int(123000000)
302: -- Iteration 4 --
303: int(-83)
304: -- Iteration 5 --
305: int(-12300000)
306: -- Iteration 6 --
307: array(10) {
308: [0]=>
309: int(1)
310: [1]=>
311: int(2)
312: [2]=>
313: int(3)
314: [3]=>
315: int(4)
316: [4]=>
317: int(5)
318: [5]=>
319: int(6)
320: [6]=>
321: int(7)
322: [7]=>
323: int(8)
324: [8]=>
325: int(9)
326: [9]=>
327: int(10)
328: }
329: -- Iteration 7 --
330: array(10) {
331: [0]=>
332: int(-1)
333: [1]=>
334: int(-2)
335: [2]=>
336: int(-3)
337: [3]=>
338: int(-4)
339: [4]=>
340: int(-5)
341: [5]=>
342: int(-6)
343: [6]=>
344: int(-7)
345: [7]=>
346: int(-8)
347: [8]=>
348: int(-9)
349: [9]=>
350: int(-10)
351: }
352: -- Iteration 8 --
353: int(2147483647)
354: -- Iteration 9 --
355: int(2147483648)
356: -- Iteration 10 --
357: int(-2147483648)
358: -- Iteration 11 --
359: int(-2147483647)
360: -- Iteration 12 --
361: int(2147483647)
362: -- Iteration 13 --
363: int(-2147483648)
364: -- Iteration 14 --
365: int(2147483647)
366: -- Iteration 15 --
367: int(-2147483648)
368:
369: *** Testing var_dump() on float variables ***
370: -- Iteration 1 --
371: float(0)
372: -- Iteration 2 --
373: float(0)
374: -- Iteration 3 --
375: float(1.234)
376: -- Iteration 4 --
377: float(-1.234)
378: -- Iteration 5 --
379: float(-2)
380: -- Iteration 6 --
381: float(2)
382: -- Iteration 7 --
383: float(-0.5)
384: -- Iteration 8 --
385: float(0.567)
386: -- Iteration 9 --
387: float(-0.00067)
388: -- Iteration 10 --
389: float(-670)
390: -- Iteration 11 --
391: float(670)
392: -- Iteration 12 --
393: float(670)
394: -- Iteration 13 --
395: float(-0.00410003)
396: -- Iteration 14 --
397: float(-4100.03)
398: -- Iteration 15 --
399: float(0.004100003)
400: -- Iteration 16 --
401: float(4100.003)
402: -- Iteration 17 --
403: float(100000)
404: -- Iteration 18 --
405: float(-100000)
406: -- Iteration 19 --
407: float(1.0E-5)
408: -- Iteration 20 --
409: float(-1.0E-5)
410: -- Iteration 21 --
411: float(100000)
412: -- Iteration 22 --
413: float(-100000)
414: -- Iteration 23 --
415: float(100000)
416: -- Iteration 24 --
417: float(-100000)
418: -- Iteration 25 --
419: float(100000)
420: -- Iteration 26 --
421: float(-100000)
422: -- Iteration 27 --
423: float(1.0E-5)
424: -- Iteration 28 --
425: float(-1.0E-5)
426: -- Iteration 29 --
427: int(-2147483649)
428: -- Iteration 30 --
429: int(2147483649)
430: -- Iteration 31 --
431: int(2147483649)
432: -- Iteration 32 --
433: int(-2147483649)
434:
435: *** Testing var_dump() on string variables ***
436: -- Iteration 1 --
437: string(0) ""
438: -- Iteration 2 --
439: string(0) ""
440: -- Iteration 3 --
441: string(1) " "
442: -- Iteration 4 --
443: string(1) " "
444: -- Iteration 5 --
445: string(1) "0"
446: -- Iteration 6 --
447: string(1) "