Annotation of embedaddon/php/ext/standard/tests/general_functions/gettype_settype_variation1.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test gettype() & settype() functions : usage variatoins
! 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 null type.
! 20: Set type of the data to "null" 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 "null 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 null type */
! 159: $type = "null";
! 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 null --
! 189: -- Iteration 1 --
! 190: string(4) "NULL"
! 191: bool(true)
! 192: NULL
! 193: string(4) "NULL"
! 194: -- Iteration 2 --
! 195: string(7) "boolean"
! 196: bool(true)
! 197: NULL
! 198: string(4) "NULL"
! 199: -- Iteration 3 --
! 200: string(7) "boolean"
! 201: bool(true)
! 202: NULL
! 203: string(4) "NULL"
! 204: -- Iteration 4 --
! 205: string(7) "boolean"
! 206: bool(true)
! 207: NULL
! 208: string(4) "NULL"
! 209: -- Iteration 5 --
! 210: string(6) "string"
! 211: bool(true)
! 212: NULL
! 213: string(4) "NULL"
! 214: -- Iteration 6 --
! 215: string(6) "string"
! 216: bool(true)
! 217: NULL
! 218: string(4) "NULL"
! 219: -- Iteration 7 --
! 220: string(6) "string"
! 221: bool(true)
! 222: NULL
! 223: string(4) "NULL"
! 224: -- Iteration 8 --
! 225: string(6) "string"
! 226: bool(true)
! 227: NULL
! 228: string(4) "NULL"
! 229: -- Iteration 9 --
! 230: string(6) "string"
! 231: bool(true)
! 232: NULL
! 233: string(4) "NULL"
! 234: -- Iteration 10 --
! 235: string(6) "string"
! 236: bool(true)
! 237: NULL
! 238: string(4) "NULL"
! 239: -- Iteration 11 --
! 240: string(6) "string"
! 241: bool(true)
! 242: NULL
! 243: string(4) "NULL"
! 244: -- Iteration 12 --
! 245: string(6) "string"
! 246: bool(true)
! 247: NULL
! 248: string(4) "NULL"
! 249: -- Iteration 13 --
! 250: string(6) "string"
! 251: bool(true)
! 252: NULL
! 253: string(4) "NULL"
! 254: -- Iteration 14 --
! 255: string(6) "string"
! 256: bool(true)
! 257: NULL
! 258: string(4) "NULL"
! 259: -- Iteration 15 --
! 260: string(6) "string"
! 261: bool(true)
! 262: NULL
! 263: string(4) "NULL"
! 264: -- Iteration 16 --
! 265: string(6) "string"
! 266: bool(true)
! 267: NULL
! 268: string(4) "NULL"
! 269: -- Iteration 17 --
! 270: string(6) "string"
! 271: bool(true)
! 272: NULL
! 273: string(4) "NULL"
! 274: -- Iteration 18 --
! 275: string(6) "string"
! 276: bool(true)
! 277: NULL
! 278: string(4) "NULL"
! 279: -- Iteration 19 --
! 280: string(6) "string"
! 281: bool(true)
! 282: NULL
! 283: string(4) "NULL"
! 284: -- Iteration 20 --
! 285: string(6) "string"
! 286: bool(true)
! 287: NULL
! 288: string(4) "NULL"
! 289: -- Iteration 21 --
! 290: string(6) "string"
! 291: bool(true)
! 292: NULL
! 293: string(4) "NULL"
! 294: -- Iteration 22 --
! 295: string(6) "string"
! 296: bool(true)
! 297: NULL
! 298: string(4) "NULL"
! 299: -- Iteration 23 --
! 300: string(6) "string"
! 301: bool(true)
! 302: NULL
! 303: string(4) "NULL"
! 304: -- Iteration 24 --
! 305: string(6) "string"
! 306: bool(true)
! 307: NULL
! 308: string(4) "NULL"
! 309: -- Iteration 25 --
! 310: string(6) "string"
! 311: bool(true)
! 312: NULL
! 313: string(4) "NULL"
! 314: -- Iteration 26 --
! 315: string(6) "string"
! 316: bool(true)
! 317: NULL
! 318: string(4) "NULL"
! 319: -- Iteration 27 --
! 320: string(6) "string"
! 321: bool(true)
! 322: NULL
! 323: string(4) "NULL"
! 324: -- Iteration 28 --
! 325: string(6) "string"
! 326: bool(true)
! 327: NULL
! 328: string(4) "NULL"
! 329: -- Iteration 29 --
! 330: string(6) "string"
! 331: bool(true)
! 332: NULL
! 333: string(4) "NULL"
! 334: -- Iteration 30 --
! 335: string(6) "string"
! 336: bool(true)
! 337: NULL
! 338: string(4) "NULL"
! 339: -- Iteration 31 --
! 340: string(6) "string"
! 341: bool(true)
! 342: NULL
! 343: string(4) "NULL"
! 344: -- Iteration 32 --
! 345: string(6) "string"
! 346: bool(true)
! 347: NULL
! 348: string(4) "NULL"
! 349: -- Iteration 33 --
! 350: string(6) "string"
! 351: bool(true)
! 352: NULL
! 353: string(4) "NULL"
! 354: -- Iteration 34 --
! 355: string(6) "string"
! 356: bool(true)
! 357: NULL
! 358: string(4) "NULL"
! 359: -- Iteration 35 --
! 360: string(6) "string"
! 361: bool(true)
! 362: NULL
! 363: string(4) "NULL"
! 364: -- Iteration 36 --
! 365: string(6) "string"
! 366: bool(true)
! 367: NULL
! 368: string(4) "NULL"
! 369: -- Iteration 37 --
! 370: string(6) "string"
! 371: bool(true)
! 372: NULL
! 373: string(4) "NULL"
! 374: -- Iteration 38 --
! 375: string(6) "string"
! 376: bool(true)
! 377: NULL
! 378: string(4) "NULL"
! 379: -- Iteration 39 --
! 380: string(6) "string"
! 381: bool(true)
! 382: NULL
! 383: string(4) "NULL"
! 384: -- Iteration 40 --
! 385: string(6) "string"
! 386: bool(true)
! 387: NULL
! 388: string(4) "NULL"
! 389: -- Iteration 41 --
! 390: string(6) "string"
! 391: bool(true)
! 392: NULL
! 393: string(4) "NULL"
! 394: -- Iteration 42 --
! 395: string(6) "string"
! 396: bool(true)
! 397: NULL
! 398: string(4) "NULL"
! 399: -- Iteration 43 --
! 400: string(5) "array"
! 401: bool(true)
! 402: NULL
! 403: string(4) "NULL"
! 404: -- Iteration 44 --
! 405: string(5) "array"
! 406: bool(true)
! 407: NULL
! 408: string(4) "NULL"
! 409: -- Iteration 45 --
! 410: string(5) "array"
! 411: bool(true)
! 412: NULL
! 413: string(4) "NULL"
! 414: -- Iteration 46 --
! 415: string(5) "array"
! 416: bool(true)
! 417: NULL
! 418: string(4) "NULL"
! 419: -- Iteration 47 --
! 420: string(5) "array"
! 421: bool(true)
! 422: NULL
! 423: string(4) "NULL"
! 424: -- Iteration 48 --
! 425: string(6) "double"
! 426: bool(true)
! 427: NULL
! 428: string(4) "NULL"
! 429: -- Iteration 49 --
! 430: string(7) "integer"
! 431: bool(true)
! 432: NULL
! 433: string(4) "NULL"
! 434: -- Iteration 50 --
! 435: string(6) "double"
! 436: bool(true)
! 437: NULL
! 438: string(4) "NULL"
! 439: -- Iteration 51 --
! 440: string(6) "double"
! 441: bool(true)
! 442: NULL
! 443: string(4) "NULL"
! 444: -- Iteration 52 --
! 445: string(7) "integer"
! 446: bool(true)
! 447: NULL
! 448: string(4) "NULL"
! 449: -- Iteration 53 --
! 450: string(6) "double"
! 451: bool(true)
! 452: NULL
! 453: string(4) "NULL"
! 454: -- Iteration 54 --
! 455: string(7) "integer"
! 456: bool(true)
! 457: NULL
! 458: string(4) "NULL"
! 459: -- Iteration 55 --
! 460: string(7) "integer"
! 461: bool(true)
! 462: NULL
! 463: string(4) "NULL"
! 464: -- Iteration 56 --
! 465: string(7) "integer"
! 466: bool(true)
! 467: NULL
! 468: string(4) "NULL"
! 469: -- Iteration 57 --
! 470: string(6) "double"
! 471: bool(true)
! 472: NULL
! 473: string(4) "NULL"
! 474: -- Iteration 58 --
! 475: string(6) "double"
! 476: bool(true)
! 477: NULL
! 478: string(4) "NULL"
! 479: -- Iteration 59 --
! 480: string(6) "double"
! 481: bool(true)
! 482: NULL
! 483: string(4) "NULL"
! 484: -- Iteration 60 --
! 485: string(6) "double"
! 486: bool(true)
! 487: NULL
! 488: string(4) "NULL"
! 489: -- Iteration 61 --
! 490: string(6) "double"
! 491: bool(true)
! 492: NULL
! 493: string(4) "NULL"
! 494: -- Iteration 62 --
! 495: string(6) "double"
! 496: bool(true)
! 497: NULL
! 498: string(4) "NULL"
! 499: -- Iteration 63 --
! 500: string(6) "double"
! 501: bool(true)
! 502: NULL
! 503: string(4) "NULL"
! 504: -- Iteration 64 --
! 505: string(6) "double"
! 506: bool(true)
! 507: NULL
! 508: string(4) "NULL"
! 509: -- Iteration 65 --
! 510: string(6) "double"
! 511: bool(true)
! 512: NULL
! 513: string(4) "NULL"
! 514: -- Iteration 66 --
! 515: string(6) "double"
! 516: bool(true)
! 517: NULL
! 518: string(4) "NULL"
! 519: -- Iteration 67 --
! 520: string(6) "double"
! 521: bool(true)
! 522: NULL
! 523: string(4) "NULL"
! 524: -- Iteration 68 --
! 525: string(6) "double"
! 526: bool(true)
! 527: NULL
! 528: string(4) "NULL"
! 529: -- Iteration 69 --
! 530: string(6) "double"
! 531: bool(true)
! 532: NULL
! 533: string(4) "NULL"
! 534: -- Iteration 70 --
! 535: string(6) "double"
! 536: bool(true)
! 537: NULL
! 538: string(4) "NULL"
! 539: -- Iteration 71 --
! 540: string(6) "double"
! 541: bool(true)
! 542: NULL
! 543: string(4) "NULL"
! 544: -- Iteration 72 --
! 545: string(6) "double"
! 546: bool(true)
! 547: NULL
! 548: string(4) "NULL"
! 549: -- Iteration 73 --
! 550: string(6) "double"
! 551: bool(true)
! 552: NULL
! 553: string(4) "NULL"
! 554: -- Iteration 74 --
! 555: string(6) "double"
! 556: bool(true)
! 557: NULL
! 558: string(4) "NULL"
! 559: -- Iteration 75 --
! 560: string(6) "double"
! 561: bool(true)
! 562: NULL
! 563: string(4) "NULL"
! 564: -- Iteration 76 --
! 565: string(6) "object"
! 566: bool(true)
! 567: NULL
! 568: string(4) "NULL"
! 569: -- Iteration 77 --
! 570: string(6) "object"
! 571: bool(true)
! 572: NULL
! 573: string(4) "NULL"
! 574: -- Iteration 78 --
! 575: string(6) "object"
! 576: bool(true)
! 577: NULL
! 578: string(4) "NULL"
! 579: -- Iteration 79 --
! 580: string(4) "NULL"
! 581: bool(true)
! 582: NULL
! 583: string(4) "NULL"
! 584: -- Iteration 80 --
! 585: string(4) "NULL"
! 586: bool(true)
! 587: NULL
! 588: string(4) "NULL"
! 589: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>