Annotation of embedaddon/php/ext/standard/tests/general_functions/print_r_64bit.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test print_r() 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:
! 11: <?php
! 12: /* Prototype: bool print_r ( mixed $expression [, bool $return] );
! 13: Description: Prints human-readable information about a variable
! 14: */
! 15:
! 16: /* Prototype: void check_printr( $variables )
! 17: Description: use print_r() to print variables */
! 18: function check_printr( $variables ) {
! 19: $counter = 1;
! 20: foreach( $variables as $variable ) {
! 21: echo "\n-- Iteration $counter --\n";
! 22: //default = false, prints output to screen
! 23: print_r($variable);
! 24: //$return=TRUE, print_r() will return its output, instead of printing it
! 25: $ret_string = print_r($variable, true); //$ret_string captures the output
! 26: echo "\n$ret_string\n";
! 27: //$return=false, print_r() prints the output; default behavior
! 28: print_r($variable, false);
! 29: $counter++;
! 30: }
! 31: }
! 32:
! 33: echo "\n*** Testing print_r() on integer variables ***\n";
! 34: $integers = array (
! 35: 0, // zero as argument
! 36: 000000123, //octal value of 83
! 37: 123000000,
! 38: -00000123, //octal value of 83
! 39: -12300000,
! 40: range(1,10), // positive values
! 41: range(-1,-10), // negative values
! 42: +2147483647, // max positive integer
! 43: +2147483648, // max positive integer + 1
! 44: -2147483648, // min range of integer
! 45: -2147483647, // min range of integer + 1
! 46: 0x7FFFFFFF, // max positive hexadecimal integer
! 47: -0x80000000, // min range of hexadecimal integer
! 48: 017777777777, // max posotive octal integer
! 49: -020000000000 // min range of octal integer
! 50: );
! 51: /* calling check_printr() to display contents of integer variables
! 52: using print_r() */
! 53: check_printr($integers);
! 54:
! 55: echo "\n*** Testing print_r() on float variables ***\n";
! 56: $floats = array (
! 57: -0.0,
! 58: +0.0,
! 59: 1.234,
! 60: -1.234,
! 61: -2.000000,
! 62: 000002.00,
! 63: -.5,
! 64: .567,
! 65: -.6700000e-3,
! 66: -.6700000E+3,
! 67: .6700000E+3,
! 68: .6700000e+3,
! 69: -4.10003e-3,
! 70: -4.10003E+3,
! 71: 4.100003e-3,
! 72: 4.100003E+3,
! 73: 1e5,
! 74: -1e5,
! 75: 1e-5,
! 76: -1e-5,
! 77: 1e+5,
! 78: -1e+5,
! 79: 1E5,
! 80: -1E5,
! 81: 1E+5,
! 82: -1E+5,
! 83: 1E-5,
! 84: -1E-5,
! 85: -0x80000001, // float value, beyond max negative int
! 86: 0x80000001, // float value, beyond max positive int
! 87: 020000000001, // float value, beyond max positive int
! 88: -020000000001 // float value, beyond max negative int
! 89: );
! 90: /* calling check_printr() to display contents of float variables
! 91: using print_r() */
! 92: check_printr($floats);
! 93:
! 94: echo "\n*** Testing print_r() on string variables ***\n";
! 95: $strings = array (
! 96: "",
! 97: '',
! 98: " ",
! 99: ' ',
! 100: "0",
! 101: "\0",
! 102: '\0',
! 103: "\t",
! 104: '\t',
! 105: "PHP",
! 106: 'PHP',
! 107: "abcd\x0n1234\x0005678\x0000efgh\xijkl", // strings with hexadecimal NULL
! 108: "abcd\0efgh\0ijkl\x00mnop\x000qrst\00uvwx\0000yz", // strings with octal NULL
! 109: "1234\t\n5678\n\t9100\rabcda" // strings with escape characters
! 110: );
! 111: /* calling check_printr() to display contents of strings using print_r() */
! 112: check_printr($strings);
! 113:
! 114: echo "\n*** Testing print_r() on boolean variables ***\n";
! 115: $booleans = array (
! 116: TRUE,
! 117: FALSE,
! 118: true,
! 119: false
! 120: );
! 121: /* calling check_printr() to display boolean variables using print_r() */
! 122: check_printr($booleans);
! 123: var_dump( reset($booleans) );
! 124: echo "\n";
! 125: var_dump( current($booleans) );
! 126:
! 127: echo "\n*** Testing print_r() on array variables ***\n";
! 128: $arrays = array (
! 129: array(),
! 130: array(NULL),
! 131: array(null),
! 132: array(true),
! 133: array(""),
! 134: array(''),
! 135: array(array(), array()),
! 136: array(array(1, 2), array('a', 'b')),
! 137: array(1 => 'One'),
! 138: array("test" => "is_array"),
! 139: array(0),
! 140: array(-1),
! 141: array(10.5, 5.6),
! 142: array("string", "test"),
! 143: array('string', 'test'),
! 144: );
! 145: /* calling check_printr() to display contents of $arrays */
! 146: check_printr($arrays);
! 147:
! 148: echo "\n*** Testing print_r() on object variables ***\n";
! 149: class object_class
! 150: {
! 151: var $value;
! 152: public $public_var1 = 10;
! 153: private $private_var1 = 20;
! 154: private $private_var2;
! 155: protected $protected_var1 = "string_1";
! 156: protected $protected_var2;
! 157:
! 158: function object_class ( ) {
! 159: $this->value = 50;
! 160: $this->public_var2 = 11;
! 161: $this->private_var2 = 21;
! 162: $this->protected_var2 = "string_2";
! 163: }
! 164:
! 165: public function foo1() {
! 166: echo "foo1() is called\n";
! 167: }
! 168: protected function foo2() {
! 169: echo "foo2() is called\n";
! 170: }
! 171: private function foo3() {
! 172: echo "foo3() is called\n";
! 173: }
! 174: }
! 175: /* class with no member */
! 176: class no_member_class {
! 177: // no members
! 178: }
! 179:
! 180: /* class with member as object of other class */
! 181: class contains_object_class
! 182: {
! 183: var $p = 30;
! 184: var $class_object1;
! 185: public $class_object2;
! 186: private $class_object3;
! 187: protected $class_object4;
! 188: var $no_member_class_object;
! 189:
! 190: public function func() {
! 191: echo "func() is called \n";
! 192: }
! 193:
! 194: function contains_object_class () {
! 195: $this->class_object1 = new object_class();
! 196: $this->class_object2 = new object_class();
! 197: $this->class_object3 = $this->class_object1;
! 198: $this->class_object4 = $this->class_object2;
! 199: $this->no_member_class_object = new no_member_class();
! 200: $this->class_object5 = $this; //recursive reference
! 201: }
! 202: }
! 203:
! 204: /* objects of different classes */
! 205: $obj = new contains_object_class;
! 206: $temp_class_obj = new object_class();
! 207:
! 208: /* object which is unset */
! 209: $unset_obj = new object_class();
! 210: unset($unset_obj);
! 211:
! 212: $objects = array (
! 213: new object_class,
! 214: new no_member_class,
! 215: new contains_object_class,
! 216: $obj,
! 217: $obj->class_object1,
! 218: $obj->class_object2,
! 219: $obj->no_member_class_object,
! 220: $temp_class_obj,
! 221: @$unset_obj
! 222: );
! 223: /* calling check_printr() to display contents of the objects using print_r() */
! 224: check_printr($objects);
! 225:
! 226: echo "\n** Testing print_r() on objects having circular reference **\n";
! 227: $recursion_obj1 = new object_class();
! 228: $recursion_obj2 = new object_class();
! 229: $recursion_obj1->obj = &$recursion_obj2; //circular reference
! 230: $recursion_obj2->obj = &$recursion_obj1; //circular reference
! 231: print_r($recursion_obj2);
! 232:
! 233: echo "\n*** Testing print_r() on resources ***\n";
! 234: /* file type resource */
! 235: $file_handle = fopen(__FILE__, "r");
! 236:
! 237: /* directory type resource */
! 238: $dir_handle = opendir( dirname(__FILE__) );
! 239:
! 240: $resources = array (
! 241: $file_handle,
! 242: $dir_handle
! 243: );
! 244: /* calling check_printr() to display the resource content type
! 245: using print_r() */
! 246: check_printr($resources);
! 247:
! 248: echo "\n*** Testing print_r() on different combinations of scalar
! 249: and non-scalar variables ***\n";
! 250: /* a variable which is unset */
! 251: $unset_var = 10.5;
! 252: unset($unset_var);
! 253:
! 254: /* unset file type resource */
! 255: unset($file_handle);
! 256:
! 257: $variations = array (
! 258: array( 123, -1.2345, "a" ),
! 259: array( "d", array(1, 3, 5), true, null),
! 260: array( new no_member_class, array(), false, 0 ),
! 261: array( -0.00, "Where am I?", array(7,8,9), TRUE, 'A', 987654321 ),
! 262: array( @$unset_var, 2.E+10, 100-20.9, 000004.599998 ), //unusual data
! 263: array( "array(1,2,3,4)1.0000002TRUE", @$file_handle, 111333.00+45e5, '/00\7')
! 264: );
! 265: /* calling check_printr() to display combinations of scalar and
! 266: non-scalar variables using print_r() */
! 267: check_printr($variations);
! 268:
! 269: echo "\n*** Testing print_r() on miscelleneous input arguments ***\n";
! 270: $misc_values = array (
! 271: @$unset_var,
! 272: NULL, // NULL argument
! 273: @$undef_variable, //undefined variable
! 274: null
! 275: );
! 276: /* calling check_printr() to display miscelleneous data using print_r() */
! 277: check_printr($misc_values);
! 278:
! 279: /* checking print_r() on functions */
! 280: echo "\n*** Testing print_r() on anonymous functions ***\n";
! 281: $newfunc = create_function('$a,$b', 'return "$a * $b = " . ($a * $b);');
! 282: echo "New anonymous function: $newfunc\n";
! 283: print_r( $newfunc(2, 3) );
! 284: /* creating anonymous function dynamically */
! 285: print_r( create_function('$a', 'return "$a * $a = " . ($a * $b);') );
! 286:
! 287: echo "\n\n*** Testing error conditions ***\n";
! 288: //passing zero argument
! 289: var_dump( print_r() );
! 290:
! 291: //passing more than required no. of arguments
! 292: var_dump( print_r(123, true, "abc") );
! 293:
! 294: // check when second arg is given other than boolean TRUE
! 295: var_dump( print_r ($value, "string") );
! 296:
! 297: /* closing resource handle used */
! 298: closedir($dir_handle);
! 299:
! 300: echo "Done\n";
! 301: ?>
! 302: --EXPECTF--
! 303: *** Testing print_r() on integer variables ***
! 304:
! 305: -- Iteration 1 --
! 306: 0
! 307: 0
! 308: 0
! 309: -- Iteration 2 --
! 310: 83
! 311: 83
! 312: 83
! 313: -- Iteration 3 --
! 314: 123000000
! 315: 123000000
! 316: 123000000
! 317: -- Iteration 4 --
! 318: -83
! 319: -83
! 320: -83
! 321: -- Iteration 5 --
! 322: -12300000
! 323: -12300000
! 324: -12300000
! 325: -- Iteration 6 --
! 326: Array
! 327: (
! 328: [0] => 1
! 329: [1] => 2
! 330: [2] => 3
! 331: [3] => 4
! 332: [4] => 5
! 333: [5] => 6
! 334: [6] => 7
! 335: [7] => 8
! 336: [8] => 9
! 337: [9] => 10
! 338: )
! 339:
! 340: Array
! 341: (
! 342: [0] => 1
! 343: [1] => 2
! 344: [2] => 3
! 345: [3] => 4
! 346: [4] => 5
! 347: [5] => 6
! 348: [6] => 7
! 349: [7] => 8
! 350: [8] => 9
! 351: [9] => 10
! 352: )
! 353:
! 354: Array
! 355: (
! 356: [0] => 1
! 357: [1] => 2
! 358: [2] => 3
! 359: [3] => 4
! 360: [4] => 5
! 361: [5] => 6
! 362: [6] => 7
! 363: [7] => 8
! 364: [8] => 9
! 365: [9] => 10
! 366: )
! 367:
! 368: -- Iteration 7 --
! 369: Array
! 370: (
! 371: [0] => -1
! 372: [1] => -2
! 373: [2] => -3
! 374: [3] => -4
! 375: [4] => -5
! 376: [5] => -6
! 377: [6] => -7
! 378: [7] => -8
! 379: [8] => -9
! 380: [9] => -10
! 381: )
! 382:
! 383: Array
! 384: (
! 385: [0] => -1
! 386: [1] => -2
! 387: [2] => -3
! 388: [3] => -4
! 389: [4] => -5
! 390: [5] => -6
! 391: [6] => -7
! 392: [7] => -8
! 393: [8] => -9
! 394: [9] => -10
! 395: )
! 396:
! 397: Array
! 398: (
! 399: [0] => -1
! 400: [1] => -2
! 401: [2] => -3
! 402: [3] => -4
! 403: [4] => -5
! 404: [5] => -6
! 405: [6] => -7
! 406: [7] => -8
! 407: [8] => -9
! 408: [9] => -10
! 409: )
! 410:
! 411: -- Iteration 8 --
! 412: 2147483647
! 413: 2147483647
! 414: 2147483647
! 415: -- Iteration 9 --
! 416: 2147483648
! 417: 2147483648
! 418: 2147483648
! 419: -- Iteration 10 --
! 420: -2147483648
! 421: -2147483648
! 422: -2147483648
! 423: -- Iteration 11 --
! 424: -2147483647
! 425: -2147483647
! 426: -2147483647
! 427: -- Iteration 12 --
! 428: 2147483647
! 429: 2147483647
! 430: 2147483647
! 431: -- Iteration 13 --
! 432: -2147483648
! 433: -2147483648
! 434: -2147483648
! 435: -- Iteration 14 --
! 436: 2147483647
! 437: 2147483647
! 438: 2147483647
! 439: -- Iteration 15 --
! 440: -2147483648
! 441: -2147483648
! 442: -2147483648
! 443: *** Testing print_r() on float variables ***
! 444:
! 445: -- Iteration 1 --
! 446: 0
! 447: 0
! 448: 0
! 449: -- Iteration 2 --
! 450: 0
! 451: 0
! 452: 0
! 453: -- Iteration 3 --
! 454: 1.234
! 455: 1.234
! 456: 1.234
! 457: -- Iteration 4 --
! 458: -1.234
! 459: -1.234
! 460: -1.234
! 461: -- Iteration 5 --
! 462: -2
! 463: -2
! 464: -2
! 465: -- Iteration 6 --
! 466: 2
! 467: 2
! 468: 2
! 469: -- Iteration 7 --
! 470: -0.5
! 471: -0.5
! 472: -0.5
! 473: -- Iteration 8 --
! 474: 0.567
! 475: 0.567
! 476: 0.567
! 477: -- Iteration 9 --
! 478: -0.00067
! 479: -0.00067
! 480: -0.00067
! 481: -- Iteration 10 --
! 482: -670
! 483: -670
! 484: -670
! 485: -- Iteration 11 --
! 486: 670
! 487: 670
! 488: 670
! 489: -- Iteration 12 --
! 490: 670
! 491: 670
! 492: 670
! 493: -- Iteration 13 --
! 494: -0.00410003
! 495: -0.00410003
! 496: -0.00410003
! 497: -- Iteration 14 --
! 498: -4100.03
! 499: -4100.03
! 500: -4100.03
! 501: -- Iteration 15 --
! 502: 0.004100003
! 503: 0.004100003
! 504: 0.004100003
! 505: -- Iteration 16 --
! 506: 4100.003
! 507: 4100.003
! 508: 4100.003
! 509: -- Iteration 17 --
! 510: 100000
! 511: 100000
! 512: 100000
! 513: -- Iteration 18 --
! 514: -100000
! 515: -100000
! 516: -100000
! 517: -- Iteration 19 --
! 518: 1.0E-5
! 519: 1.0E-5
! 520: 1.0E-5
! 521: -- Iteration 20 --
! 522: -1.0E-5
! 523: -1.0E-5
! 524: -1.0E-5
! 525: -- Iteration 21 --
! 526: 100000
! 527: 100000
! 528: 100000
! 529: -- Iteration 22 --
! 530: -100000
! 531: -100000
! 532: -100000
! 533: -- Iteration 23 --
! 534: 100000
! 535: 100000
! 536: 100000
! 537: -- Iteration 24 --
! 538: -100000
! 539: -100000
! 540: -100000
! 541: -- Iteration 25 --
! 542: 100000
! 543: 100000
! 544: 100000
! 545: -- Iteration 26 --
! 546: -100000
! 547: -100000
! 548: -100000
! 549: -- Iteration 27 --
! 550: 1.0E-5
! 551: 1.0E-5
! 552: 1.0E-5
! 553: -- Iteration 28 --
! 554: -1.0E-5
! 555: -1.0E-5
! 556: -1.0E-5
! 557: -- Iteration 29 --
! 558: -2147483649
! 559: -2147483649
! 560: -2147483649
! 561: -- Iteration 30 --
! 562: 2147483649
! 563: 2147483649
! 564: 2147483649
! 565: -- Iteration 31 --
! 566: 2147483649
! 567: 2147483649
! 568: 2147483649
! 569: -- Iteration 32 --
! 570: -2147483649
! 571: -2147483649
! 572: -2147483649
! 573: *** Testing print_r() on string variables ***
! 574:
! 575: -- Iteration 1 --
! 576:
! 577:
! 578:
! 579: -- Iteration 2 --
! 580:
! 581:
! 582:
! 583: -- Iteration 3 --
! 584:
! 585:
! 586:
! 587: -- Iteration 4 --
! 588:
! 589:
! 590:
! 591: -- Iteration 5 --
! 592: 0
! 593: 0
! 594: 0
! 595: -- Iteration 6 --
! 596: