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