2 Test var_dump() function
5 if (PHP_INT_SIZE != 8) die("skip this test is for 64bit platform only");
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.
15 /* Prototype: void check_vardump( $variables );
16 Description: use var_dump() to display the variables */
17 function check_vardump( $variables ) {
19 foreach( $variables as $variable ) {
20 echo "-- Iteration $counter --\n";
26 echo "\n*** Testing var_dump() on integer variables ***\n";
28 0, // zero as argument
29 000000123, //octal value of 83
31 -00000123, //octal value of 83
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
44 /* calling check_vardump() to display contents of integer variables
46 check_vardump($integers);
48 echo "\n*** Testing var_dump() on float variables ***\n";
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
83 /* calling check_vardump() to display contents of float variables
85 check_vardump($floats);
87 echo "\n*** Testing var_dump() on string variables ***\n";
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\"abcda" // strings with escape characters
104 /* calling check_vardump() to display contents of strings
106 check_vardump($strings);
108 echo "\n*** Testing var_dump() on boolean variables ***\n";
115 /* calling check_vardump() to display boolean variables
117 check_vardump($booleans);
119 echo "\n*** Testing var_dump() on array variables ***\n";
127 array(array(), array()),
128 array(array(1, 2), array('a', 'b')),
130 array("test" => "is_array"),
134 array("string", "test"),
135 array('string', 'test'),
137 /* calling check_vardump() to display contents of an array
139 check_vardump($arrays);
141 echo "\n*** Testing var_dump() on object variables ***\n";
145 public $public_var1 = 10;
146 private $private_var1 = 20;
147 private $private_var2;
148 protected $protected_var1 = "string_1";
149 protected $protected_var2;
151 function __construct ( ) {
153 $this->public_var2 = 11;
154 $this->private_var2 = 21;
155 $this->protected_var2 = "string_2";
158 public function foo1() {
159 echo "foo1() is called\n";
161 protected function foo2() {
162 echo "foo2() is called\n";
164 private function foo3() {
165 echo "foo3() is called\n";
168 /* class with no member */
169 class no_member_class {
173 /* class with member as object of other class */
174 class contains_object_class
178 public $class_object2;
179 private $class_object3;
180 protected $class_object4;
181 var $no_member_class_object;
183 public function func() {
184 echo "func() is called \n";
187 function __construct () {
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
197 /* objects of different classes */
198 $obj = new contains_object_class;
199 $temp_class_obj = new object_class();
201 /* object which is unset */
202 $unset_obj = new object_class();
208 new contains_object_class,
212 $obj->no_member_class_object,
216 /* calling check_vardump() to display contents of the objects
218 check_vardump($objects);
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);
227 echo "\n*** Testing var_dump() on resources ***\n";
228 /* file type resource */
229 $file_handle = fopen(__FILE__, "r");
231 /* directory type resource */
232 $dir_handle = opendir( __DIR__ );
238 /* calling check_vardump() to display the resource content type
240 check_vardump($resources);
242 echo "\n*** Testing var_dump() on different combinations of scalar
243 and non-scalar variables ***\n";
244 /* a variable which is unset */
248 /* unset file type resource */
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')
259 /* calling check_vardump() to display combinations of scalar and
260 non-scalar variables using var_dump() */
261 check_vardump($variations);
263 echo "\n*** Testing var_dump() on miscellaneous input arguments ***\n";
264 $misc_values = array (
266 NULL, // NULL argument
267 @$undef_variable, //undefined variable
270 /* calling check_vardump() to display miscellaneous data using var_dump() */
271 check_vardump($misc_values);
273 echo "\n*** Testing var_dump() on multiple arguments ***\n";
274 var_dump( $integers, $floats, $strings, $arrays, $booleans, $resources,
275 $objects, $misc_values, $variations );
277 /* closing resource handle used */
278 closedir($dir_handle);
283 *** Testing var_dump() on integer variables ***
357 *** Testing var_dump() on float variables ***
423 *** Testing var_dump() on string variables ***
447 string(29) "abcd
\0n1234
\005678
\000efgh\xijkl"
449 string(34) "abcd
\0efgh
\0ijkl
\0mnop
\00qrst
\0uvwx
\00yz"
455 *** Testing var_dump() on boolean variables ***
465 *** Testing var_dump() on array variables ***
562 *** Testing var_dump() on object variables ***
564 object(object_class)#6 (7) {
569 ["private_var1":"object_class":private]=>
571 ["private_var2":"object_class":private]=>
573 ["protected_var1":protected]=>
575 ["protected_var2":protected]=>
581 object(no_member_class)#7 (0) {
584 object(contains_object_class)#8 (7) {
588 object(object_class)#9 (7) {
593 ["private_var1":"object_class":private]=>
595 ["private_var2":"object_class":private]=>
597 ["protected_var1":protected]=>
599 ["protected_var2":protected]=>
605 object(object_class)#10 (7) {
610 ["private_var1":"object_class":private]=>
612 ["private_var2":"object_class":private]=>
614 ["protected_var1":protected]=>
616 ["protected_var2":protected]=>
621 ["class_object3":"contains_object_class":private]=>
622 object(object_class)#9 (7) {
627 ["private_var1":"object_class":private]=>
629 ["private_var2":"object_class":private]=>
631 ["protected_var1":protected]=>
633 ["protected_var2":protected]=>
638 ["class_object4":protected]=>
639 object(object_class)#10 (7) {
644 ["private_var1":"object_class":private]=>
646 ["private_var2":"object_class":private]=>
648 ["protected_var1":protected]=>
650 ["protected_var2":protected]=>
655 ["no_member_class_object"]=>
656 object(no_member_class)#11 (0) {
662 object(contains_object_class)#1 (7) {
666 object(object_class)#2 (7) {
671 ["private_var1":"object_class":private]=>
673 ["private_var2":"object_class":private]=>
675 ["protected_var1":protected]=>
677 ["protected_var2":protected]=>
683 object(object_class)#3 (7) {
688 ["private_var1":"object_class":private]=>
690 ["private_var2":"object_class":private]=>
692 ["protected_var1":protected]=>
694 ["protected_var2":protected]=>
699 ["class_object3":"contains_object_class":private]=>
700 object(object_class)#2 (7) {
705 ["private_var1":"object_class":private]=>
707 ["private_var2":"object_class":private]=>
709 ["protected_var1":protected]=>
711 ["protected_var2":protected]=>
716 ["class_object4":protected]=>
717 object(object_class)#3 (7) {
722 ["private_var1":"object_class":private]=>
724 ["private_var2":"object_class":private]=>
726 ["protected_var1":protected]=>
728 ["protected_var2":protected]=>
733 ["no_member_class_object"]=>
734 object(no_member_class)#4 (0) {
740 object(object_class)#2 (7) {
745 ["private_var1":"object_class":private]=>
747 ["private_var2":"object_class":private]=>
749 ["protected_var1":protected]=>
751 ["protected_var2":protected]=>
757 object(object_class)#3 (7) {
762 ["private_var1":"object_class":private]=>
764 ["private_var2":"object_class":private]=>
766 ["protected_var1":protected]=>
768 ["protected_var2":protected]=>
774 object(no_member_class)#4 (0) {
777 object(object_class)#5 (7) {
782 ["private_var1":"object_class":private]=>
784 ["private_var2":"object_class":private]=>
786 ["protected_var1":protected]=>
788 ["protected_var2":protected]=>
796 ** Testing var_dump() on objects having circular reference **
797 object(object_class)#13 (8) {
802 ["private_var1":"object_class":private]=>
804 ["private_var2":"object_class":private]=>
806 ["protected_var1":protected]=>
808 ["protected_var2":protected]=>
813 &object(object_class)#12 (8) {
818 ["private_var1":"object_class":private]=>
820 ["private_var2":"object_class":private]=>
822 ["protected_var1":protected]=>
824 ["protected_var2":protected]=>
833 *** Testing var_dump() on resources ***
835 resource(5) of type (stream)
837 resource(6) of type (stream)
839 *** Testing var_dump() on different combinations of scalar
840 and non-scalar variables ***
871 object(no_member_class)#14 (0) {
886 string(11) "Where am I?"
917 string(27) "array(1,2,3,4)1.0000002TRUE"
926 *** Testing var_dump() on miscellaneous input arguments ***
936 *** Testing var_dump() on multiple arguments ***
1101 string(29) "abcd
\0n1234
\005678
\000efgh\xijkl"
1103 string(34) "abcd
\0efgh
\0ijkl
\0mnop
\00qrst
\0uvwx
\00yz"
1172 string(8) "is_array"
1218 resource(5) of type (stream)
1220 resource(6) of type (stream)
1224 object(object_class)#6 (7) {
1229 ["private_var1":"object_class":private]=>
1231 ["private_var2":"object_class":private]=>
1233 ["protected_var1":protected]=>
1234 string(8) "string_1"
1235 ["protected_var2":protected]=>
1236 string(8) "string_2"
1241 object(no_member_class)#7 (0) {
1244 object(contains_object_class)#8 (7) {
1248 object(object_class)#9 (7) {
1253 ["private_var1":"object_class":private]=>
1255 ["private_var2":"object_class":private]=>
1257 ["protected_var1":protected]=>
1258 string(8) "string_1"
1259 ["protected_var2":protected]=>
1260 string(8) "string_2"
1265 object(object_class)#10 (7) {
1270 ["private_var1":"object_class":private]=>
1272 ["private_var2":"object_class":private]=>
1274 ["protected_var1":protected]=>
1275 string(8) "string_1"
1276 ["protected_var2":protected]=>
1277 string(8) "string_2"
1281 ["class_object3":"contains_object_class":private]=>
1282 object(object_class)#9 (7) {
1287 ["private_var1":"object_class":private]=>
1289 ["private_var2":"object_class":private]=>
1291 ["protected_var1":protected]=>
1292 string(8) "string_1"
1293 ["protected_var2":protected]=>
1294 string(8) "string_2"
1298 ["class_object4":protected]=>
1299 object(object_class)#10 (7) {
1304 ["private_var1":"object_class":private]=>
1306 ["private_var2":"object_class":private]=>
1308 ["protected_var1":protected]=>
1309 string(8) "string_1"
1310 ["protected_var2":protected]=>
1311 string(8) "string_2"
1315 ["no_member_class_object"]=>
1316 object(no_member_class)#11 (0) {
1322 object(contains_object_class)#1 (7) {
1326 object(object_class)#2 (7) {
1331 ["private_var1":"object_class":private]=>
1333 ["private_var2":"object_class":private]=>
1335 ["protected_var1":protected]=>
1336 string(8) "string_1"
1337 ["protected_var2":protected]=>
1338 string(8) "string_2"
1343 object(object_class)#3 (7) {
1348 ["private_var1":"object_class":private]=>
1350 ["private_var2":"object_class":private]=>
1352 ["protected_var1":protected]=>
1353 string(8) "string_1"
1354 ["protected_var2":protected]=>
1355 string(8) "string_2"
1359 ["class_object3":"contains_object_class":private]=>
1360 object(object_class)#2 (7) {
1365 ["private_var1":"object_class":private]=>
1367 ["private_var2":"object_class":private]=>
1369 ["protected_var1":protected]=>
1370 string(8) "string_1"
1371 ["protected_var2":protected]=>
1372 string(8) "string_2"
1376 ["class_object4":protected]=>
1377 object(object_class)#3 (7) {
1382 ["private_var1":"object_class":private]=>
1384 ["private_var2":"object_class":private]=>
1386 ["protected_var1":protected]=>
1387 string(8) "string_1"
1388 ["protected_var2":protected]=>
1389 string(8) "string_2"
1393 ["no_member_class_object"]=>
1394 object(no_member_class)#4 (0) {
1400 object(object_class)#2 (7) {
1405 ["private_var1":"object_class":private]=>
1407 ["private_var2":"object_class":private]=>
1409 ["protected_var1":protected]=>
1410 string(8) "string_1"
1411 ["protected_var2":protected]=>
1412 string(8) "string_2"
1417 object(object_class)#3 (7) {
1422 ["private_var1":"object_class":private]=>
1424 ["private_var2":"object_class":private]=>
1426 ["protected_var1":protected]=>
1427 string(8) "string_1"
1428 ["protected_var2":protected]=>
1429 string(8) "string_2"
1434 object(no_member_class)#4 (0) {
1437 object(object_class)#5 (7) {
1442 ["private_var1":"object_class":private]=>
1444 ["private_var2":"object_class":private]=>
1446 ["protected_var1":protected]=>
1447 string(8) "string_1"
1448 ["protected_var2":protected]=>
1449 string(8) "string_2"
1497 object(no_member_class)#14 (0) {
1512 string(11) "Where am I?"
1543 string(27) "array(1,2,3,4)1.0000002TRUE"