Annotation of embedaddon/php/ext/standard/tests/general_functions/gettype_settype_variation8.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test gettype() & settype() functions : usage variations
! 3: --SKIPIF--
! 4: <?php
! 5: if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platform only");
! 6: ?>
! 7: --INI--
! 8: precision=14
! 9: --FILE--
! 10: <?php
! 11: /* Prototype: string gettype ( mixed $var );
! 12: Description: Returns the type of the PHP variable var
! 13:
! 14: Prototype: bool settype ( mixed &$var, string $type );
! 15: Description: Set the type of variable var to type
! 16: */
! 17:
! 18: /* Test usage variation of gettype() and settype() functions:
! 19: settype() to string type.
! 20: Set type of the data to "string" and verify using gettype
! 21: Following are performed in the listed sequence:
! 22: get the current type of the variable
! 23: set the type of the variable to string type
! 24: dump the variable to see its new data
! 25: get the new type of the variable
! 26: */
! 27:
! 28: /* function to handle catchable errors */
! 29: function foo($errno, $errstr, $errfile, $errline) {
! 30: // var_dump($errstr);
! 31: // print error no and error string
! 32: echo "$errno: $errstr\n";
! 33: }
! 34: //set the error handler, this is required as
! 35: // settype() would fail with catachable fatal error
! 36: set_error_handler("foo");
! 37:
! 38: $var1 = "another string";
! 39: $var2 = array(2,3,4);
! 40:
! 41: // a variable which is unset
! 42: $unset_var = 10.5;
! 43: unset( $unset_var );
! 44:
! 45: class point
! 46: {
! 47: var $x;
! 48: var $y;
! 49:
! 50: function point($x, $y) {
! 51: $this->x = $x;
! 52: $this->y = $y;
! 53: }
! 54:
! 55: function __toString() {
! 56: return "ObjectPoint";
! 57: }
! 58: }
! 59:
! 60: $var_values = array (
! 61: /* nulls */
! 62: null,
! 63:
! 64: /* boolean */
! 65: FALSE,
! 66: TRUE,
! 67: true,
! 68:
! 69: /* strings */
! 70: "\xFF",
! 71: "\x66",
! 72: "\0123",
! 73: "",
! 74: '',
! 75: " ",
! 76: ' ',
! 77: /* numerics in the form of string */
! 78: '10',
! 79: "10",
! 80: "10string",
! 81: '10string',
! 82: "1",
! 83: "-1",
! 84: "1e2",
! 85: " 1",
! 86: "2974394749328742328432",
! 87: "-1e-2",
! 88: '1',
! 89: '-1',
! 90: '1e2',
! 91: ' 1',
! 92: '2974394749328742328432',
! 93: '-1e-2',
! 94: "0xff",
! 95: '0x55',
! 96: '0XA55',
! 97: '0X123',
! 98: "0123",
! 99: '0123',
! 100: "-0123",
! 101: "+0123",
! 102: '-0123',
! 103: '+0123',
! 104: "-0x80001", // invalid numerics as its prefix with sign or have decimal points
! 105: "+0x80001",
! 106: "-0x80001.5",
! 107: "0x80001.5",
! 108: "@$%#$%^$%^&^",
! 109:
! 110: /* arrays */
! 111: array(),
! 112: array(NULL),
! 113: array(1,2,3,4),
! 114: array(1 => "one", 2 => "two", "3" => "three", "four" => 4),
! 115: array(1.5, 2.4, 6.5e6),
! 116:
! 117: /* integers */
! 118: -2147483648, // max -ne int value
! 119: 2147483647,
! 120: 2147483649,
! 121: 1232147483649,
! 122: 0x55,
! 123: 0xF674593039, // a hex value > than max int
! 124: -0X558F,
! 125: 0555,
! 126: -0555,
! 127: 02224242434343152, // an octal value > than max int
! 128:
! 129: /* floats */
! 130: 1e5,
! 131: -1e5,
! 132: 1E5,
! 133: -1E5,
! 134: -1.5,
! 135: .5,
! 136: -.5,
! 137: .5e6,
! 138: -.5e6,
! 139: -.5e-6,
! 140: .5e+6,
! 141: -.5e+6,
! 142: .512E6,
! 143: -.512E6,
! 144: .512E-6,
! 145: +.512E-6,
! 146: .512E+6,
! 147: -.512E+6,
! 148:
! 149: new point(NULL, NULL),
! 150: new point(2.5, 40.5),
! 151: new point(0, 0),
! 152:
! 153: /* undefined/unset vars */
! 154: $unset_var,
! 155: $undef_var
! 156: );
! 157:
! 158: /* test conversion to string type */
! 159: $type = "string";
! 160:
! 161: echo "\n*** Testing gettype() & settype() functions : usage variations ***\n";
! 162: echo "\n-- Setting type of data to $type --\n";
! 163: $loop_count = 1;
! 164: foreach ($var_values as $var) {
! 165: echo "-- Iteration $loop_count --\n"; $loop_count++;
! 166:
! 167: // get the current data type
! 168: var_dump( gettype($var) );
! 169:
! 170: // convert it to null
! 171: var_dump( settype($var, $type) );
! 172:
! 173: // dump the converted data
! 174: var_dump( $var );
! 175:
! 176: // check the new type after conversion
! 177: var_dump( gettype($var) );
! 178: }
! 179:
! 180: echo "Done\n";
! 181: ?>
! 182: --EXPECTF--
! 183: 8: Undefined variable: unset_var
! 184: 8: Undefined variable: undef_var
! 185:
! 186: *** Testing gettype() & settype() functions : usage variations ***
! 187:
! 188: -- Setting type of data to string --
! 189: -- Iteration 1 --
! 190: string(4) "NULL"
! 191: bool(true)
! 192: string(0) ""
! 193: string(6) "string"
! 194: -- Iteration 2 --
! 195: string(7) "boolean"
! 196: bool(true)
! 197: string(0) ""
! 198: string(6) "string"
! 199: -- Iteration 3 --
! 200: string(7) "boolean"
! 201: bool(true)
! 202: string(1) "1"
! 203: string(6) "string"
! 204: -- Iteration 4 --
! 205: string(7) "boolean"
! 206: bool(true)
! 207: string(1) "1"
! 208: string(6) "string"
! 209: -- Iteration 5 --
! 210: string(6) "string"
! 211: bool(true)
! 212: string(1) "ÿ"
! 213: string(6) "string"
! 214: -- Iteration 6 --
! 215: string(6) "string"
! 216: bool(true)
! 217: string(1) "f"
! 218: string(6) "string"
! 219: -- Iteration 7 --
! 220: string(6) "string"
! 221: bool(true)
! 222: string(2) "
! 223: 3"
! 224: string(6) "string"
! 225: -- Iteration 8 --
! 226: string(6) "string"
! 227: bool(true)
! 228: string(0) ""
! 229: string(6) "string"
! 230: -- Iteration 9 --
! 231: string(6) "string"
! 232: bool(true)
! 233: string(0) ""
! 234: string(6) "string"
! 235: -- Iteration 10 --
! 236: string(6) "string"
! 237: bool(true)
! 238: string(1) " "
! 239: string(6) "string"
! 240: -- Iteration 11 --
! 241: string(6) "string"
! 242: bool(true)
! 243: string(1) " "
! 244: string(6) "string"
! 245: -- Iteration 12 --
! 246: string(6) "string"
! 247: bool(true)
! 248: string(2) "10"
! 249: string(6) "string"
! 250: -- Iteration 13 --
! 251: string(6) "string"
! 252: bool(true)
! 253: string(2) "10"
! 254: string(6) "string"
! 255: -- Iteration 14 --
! 256: string(6) "string"
! 257: bool(true)
! 258: string(8) "10string"
! 259: string(6) "string"
! 260: -- Iteration 15 --
! 261: string(6) "string"
! 262: bool(true)
! 263: string(8) "10string"
! 264: string(6) "string"
! 265: -- Iteration 16 --
! 266: string(6) "string"
! 267: bool(true)
! 268: string(1) "1"
! 269: string(6) "string"
! 270: -- Iteration 17 --
! 271: string(6) "string"
! 272: bool(true)
! 273: string(2) "-1"
! 274: string(6) "string"
! 275: -- Iteration 18 --
! 276: string(6) "string"
! 277: bool(true)
! 278: string(3) "1e2"
! 279: string(6) "string"
! 280: -- Iteration 19 --
! 281: string(6) "string"
! 282: bool(true)
! 283: string(2) " 1"
! 284: string(6) "string"
! 285: -- Iteration 20 --
! 286: string(6) "string"
! 287: bool(true)
! 288: string(22) "2974394749328742328432"
! 289: string(6) "string"
! 290: -- Iteration 21 --
! 291: string(6) "string"
! 292: bool(true)
! 293: string(5) "-1e-2"
! 294: string(6) "string"
! 295: -- Iteration 22 --
! 296: string(6) "string"
! 297: bool(true)
! 298: string(1) "1"
! 299: string(6) "string"
! 300: -- Iteration 23 --
! 301: string(6) "string"
! 302: bool(true)
! 303: string(2) "-1"
! 304: string(6) "string"
! 305: -- Iteration 24 --
! 306: string(6) "string"
! 307: bool(true)
! 308: string(3) "1e2"
! 309: string(6) "string"
! 310: -- Iteration 25 --
! 311: string(6) "string"
! 312: bool(true)
! 313: string(2) " 1"
! 314: string(6) "string"
! 315: -- Iteration 26 --
! 316: string(6) "string"
! 317: bool(true)
! 318: string(22) "2974394749328742328432"
! 319: string(6) "string"
! 320: -- Iteration 27 --
! 321: string(6) "string"
! 322: bool(true)
! 323: string(5) "-1e-2"
! 324: string(6) "string"
! 325: -- Iteration 28 --
! 326: string(6) "string"
! 327: bool(true)
! 328: string(4) "0xff"
! 329: string(6) "string"
! 330: -- Iteration 29 --
! 331: string(6) "string"
! 332: bool(true)
! 333: string(4) "0x55"
! 334: string(6) "string"
! 335: -- Iteration 30 --
! 336: string(6) "string"
! 337: bool(true)
! 338: string(5) "0XA55"
! 339: string(6) "string"
! 340: -- Iteration 31 --
! 341: string(6) "string"
! 342: bool(true)
! 343: string(5) "0X123"
! 344: string(6) "string"
! 345: -- Iteration 32 --
! 346: string(6) "string"
! 347: bool(true)
! 348: string(4) "0123"
! 349: string(6) "string"
! 350: -- Iteration 33 --
! 351: string(6) "string"
! 352: bool(true)
! 353: string(4) "0123"
! 354: string(6) "string"
! 355: -- Iteration 34 --
! 356: string(6) "string"
! 357: bool(true)
! 358: string(5) "-0123"
! 359: string(6) "string"
! 360: -- Iteration 35 --
! 361: string(6) "string"
! 362: bool(true)
! 363: string(5) "+0123"
! 364: string(6) "string"
! 365: -- Iteration 36 --
! 366: string(6) "string"
! 367: bool(true)
! 368: string(5) "-0123"
! 369: string(6) "string"
! 370: -- Iteration 37 --
! 371: string(6) "string"
! 372: bool(true)
! 373: string(5) "+0123"
! 374: string(6) "string"
! 375: -- Iteration 38 --
! 376: string(6) "string"
! 377: bool(true)
! 378: string(8) "-0x80001"
! 379: string(6) "string"
! 380: -- Iteration 39 --
! 381: string(6) "string"
! 382: bool(true)
! 383: string(8) "+0x80001"
! 384: string(6) "string"
! 385: -- Iteration 40 --
! 386: string(6) "string"
! 387: bool(true)
! 388: string(10) "-0x80001.5"
! 389: string(6) "string"
! 390: -- Iteration 41 --
! 391: string(6) "string"
! 392: bool(true)
! 393: string(9) "0x80001.5"
! 394: string(6) "string"
! 395: -- Iteration 42 --
! 396: string(6) "string"
! 397: bool(true)
! 398: string(12) "@$%#$%^$%^&^"
! 399: string(6) "string"
! 400: -- Iteration 43 --
! 401: string(5) "array"
! 402: 8: Array to string conversion
! 403: bool(true)
! 404: string(5) "Array"
! 405: string(6) "string"
! 406: -- Iteration 44 --
! 407: string(5) "array"
! 408: 8: Array to string conversion
! 409: bool(true)
! 410: string(5) "Array"
! 411: string(6) "string"
! 412: -- Iteration 45 --
! 413: string(5) "array"
! 414: 8: Array to string conversion
! 415: bool(true)
! 416: string(5) "Array"
! 417: string(6) "string"
! 418: -- Iteration 46 --
! 419: string(5) "array"
! 420: 8: Array to string conversion
! 421: bool(true)
! 422: string(5) "Array"
! 423: string(6) "string"
! 424: -- Iteration 47 --
! 425: string(5) "array"
! 426: 8: Array to string conversion
! 427: bool(true)
! 428: string(5) "Array"
! 429: string(6) "string"
! 430: -- Iteration 48 --
! 431: string(6) "double"
! 432: bool(true)
! 433: string(11) "-2147483648"
! 434: string(6) "string"
! 435: -- Iteration 49 --
! 436: string(7) "integer"
! 437: bool(true)
! 438: string(10) "2147483647"
! 439: string(6) "string"
! 440: -- Iteration 50 --
! 441: string(6) "double"
! 442: bool(true)
! 443: string(10) "2147483649"
! 444: string(6) "string"
! 445: -- Iteration 51 --
! 446: string(6) "double"
! 447: bool(true)
! 448: string(13) "1232147483649"
! 449: string(6) "string"
! 450: -- Iteration 52 --
! 451: string(7) "integer"
! 452: bool(true)
! 453: string(2) "85"
! 454: string(6) "string"
! 455: -- Iteration 53 --
! 456: string(6) "double"
! 457: bool(true)
! 458: string(13) "1058513956921"
! 459: string(6) "string"
! 460: -- Iteration 54 --
! 461: string(7) "integer"
! 462: bool(true)
! 463: string(6) "-21903"
! 464: string(6) "string"
! 465: -- Iteration 55 --
! 466: string(7) "integer"
! 467: bool(true)
! 468: string(3) "365"
! 469: string(6) "string"
! 470: -- Iteration 56 --
! 471: string(7) "integer"
! 472: bool(true)
! 473: string(4) "-365"
! 474: string(6) "string"
! 475: -- Iteration 57 --
! 476: string(6) "double"
! 477: bool(true)
! 478: string(14) "80561044571754"
! 479: string(6) "string"
! 480: -- Iteration 58 --
! 481: string(6) "double"
! 482: bool(true)
! 483: string(6) "100000"
! 484: string(6) "string"
! 485: -- Iteration 59 --
! 486: string(6) "double"
! 487: bool(true)
! 488: string(7) "-100000"
! 489: string(6) "string"
! 490: -- Iteration 60 --
! 491: string(6) "double"
! 492: bool(true)
! 493: string(6) "100000"
! 494: string(6) "string"
! 495: -- Iteration 61 --
! 496: string(6) "double"
! 497: bool(true)
! 498: string(7) "-100000"
! 499: string(6) "string"
! 500: -- Iteration 62 --
! 501: string(6) "double"
! 502: bool(true)
! 503: string(4) "-1.5"
! 504: string(6) "string"
! 505: -- Iteration 63 --
! 506: string(6) "double"
! 507: bool(true)
! 508: string(3) "0.5"
! 509: string(6) "string"
! 510: -- Iteration 64 --
! 511: string(6) "double"
! 512: bool(true)
! 513: string(4) "-0.5"
! 514: string(6) "string"
! 515: -- Iteration 65 --
! 516: string(6) "double"
! 517: bool(true)
! 518: string(6) "500000"
! 519: string(6) "string"
! 520: -- Iteration 66 --
! 521: string(6) "double"
! 522: bool(true)
! 523: string(7) "-500000"
! 524: string(6) "string"
! 525: -- Iteration 67 --
! 526: string(6) "double"
! 527: bool(true)
! 528: string(7) "-5.0E-7"
! 529: string(6) "string"
! 530: -- Iteration 68 --
! 531: string(6) "double"
! 532: bool(true)
! 533: string(6) "500000"
! 534: string(6) "string"
! 535: -- Iteration 69 --
! 536: string(6) "double"
! 537: bool(true)
! 538: string(7) "-500000"
! 539: string(6) "string"
! 540: -- Iteration 70 --
! 541: string(6) "double"
! 542: bool(true)
! 543: string(6) "512000"
! 544: string(6) "string"
! 545: -- Iteration 71 --
! 546: string(6) "double"
! 547: bool(true)
! 548: string(7) "-512000"
! 549: string(6) "string"
! 550: -- Iteration 72 --
! 551: string(6) "double"
! 552: bool(true)
! 553: string(7) "5.12E-7"
! 554: string(6) "string"
! 555: -- Iteration 73 --
! 556: string(6) "double"
! 557: bool(true)
! 558: string(7) "5.12E-7"
! 559: string(6) "string"
! 560: -- Iteration 74 --
! 561: string(6) "double"
! 562: bool(true)
! 563: string(6) "512000"
! 564: string(6) "string"
! 565: -- Iteration 75 --
! 566: string(6) "double"
! 567: bool(true)
! 568: string(7) "-512000"
! 569: string(6) "string"
! 570: -- Iteration 76 --
! 571: string(6) "object"
! 572: bool(true)
! 573: string(11) "ObjectPoint"
! 574: string(6) "string"
! 575: -- Iteration 77 --
! 576: string(6) "object"
! 577: bool(true)
! 578: string(11) "ObjectPoint"
! 579: string(6) "string"
! 580: -- Iteration 78 --
! 581: string(6) "object"
! 582: bool(true)
! 583: string(11) "ObjectPoint"
! 584: string(6) "string"
! 585: -- Iteration 79 --
! 586: string(4) "NULL"
! 587: bool(true)
! 588: string(0) ""
! 589: string(6) "string"
! 590: -- Iteration 80 --
! 591: string(4) "NULL"
! 592: bool(true)
! 593: string(0) ""
! 594: string(6) "string"
! 595: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>