Annotation of embedaddon/php/ext/standard/tests/general_functions/gettype_settype_variation5.phpt, revision 1.1.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 resource type.
                     20:    Set type of the data to "resource" 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 resource 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 resource type */
                    159: $type = "resource";
                    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 resource --
                    189: -- Iteration 1 --
                    190: string(4) "NULL"
                    191: 2: settype(): Cannot convert to resource type
                    192: bool(false)
                    193: NULL
                    194: string(4) "NULL"
                    195: -- Iteration 2 --
                    196: string(7) "boolean"
                    197: 2: settype(): Cannot convert to resource type
                    198: bool(false)
                    199: bool(false)
                    200: string(7) "boolean"
                    201: -- Iteration 3 --
                    202: string(7) "boolean"
                    203: 2: settype(): Cannot convert to resource type
                    204: bool(false)
                    205: bool(true)
                    206: string(7) "boolean"
                    207: -- Iteration 4 --
                    208: string(7) "boolean"
                    209: 2: settype(): Cannot convert to resource type
                    210: bool(false)
                    211: bool(true)
                    212: string(7) "boolean"
                    213: -- Iteration 5 --
                    214: string(6) "string"
                    215: 2: settype(): Cannot convert to resource type
                    216: bool(false)
                    217: string(1) "ÿ"
                    218: string(6) "string"
                    219: -- Iteration 6 --
                    220: string(6) "string"
                    221: 2: settype(): Cannot convert to resource type
                    222: bool(false)
                    223: string(1) "f"
                    224: string(6) "string"
                    225: -- Iteration 7 --
                    226: string(6) "string"
                    227: 2: settype(): Cannot convert to resource type
                    228: bool(false)
                    229: string(2) "
                    230: 3"
                    231: string(6) "string"
                    232: -- Iteration 8 --
                    233: string(6) "string"
                    234: 2: settype(): Cannot convert to resource type
                    235: bool(false)
                    236: string(0) ""
                    237: string(6) "string"
                    238: -- Iteration 9 --
                    239: string(6) "string"
                    240: 2: settype(): Cannot convert to resource type
                    241: bool(false)
                    242: string(0) ""
                    243: string(6) "string"
                    244: -- Iteration 10 --
                    245: string(6) "string"
                    246: 2: settype(): Cannot convert to resource type
                    247: bool(false)
                    248: string(1) " "
                    249: string(6) "string"
                    250: -- Iteration 11 --
                    251: string(6) "string"
                    252: 2: settype(): Cannot convert to resource type
                    253: bool(false)
                    254: string(1) " "
                    255: string(6) "string"
                    256: -- Iteration 12 --
                    257: string(6) "string"
                    258: 2: settype(): Cannot convert to resource type
                    259: bool(false)
                    260: string(2) "10"
                    261: string(6) "string"
                    262: -- Iteration 13 --
                    263: string(6) "string"
                    264: 2: settype(): Cannot convert to resource type
                    265: bool(false)
                    266: string(2) "10"
                    267: string(6) "string"
                    268: -- Iteration 14 --
                    269: string(6) "string"
                    270: 2: settype(): Cannot convert to resource type
                    271: bool(false)
                    272: string(8) "10string"
                    273: string(6) "string"
                    274: -- Iteration 15 --
                    275: string(6) "string"
                    276: 2: settype(): Cannot convert to resource type
                    277: bool(false)
                    278: string(8) "10string"
                    279: string(6) "string"
                    280: -- Iteration 16 --
                    281: string(6) "string"
                    282: 2: settype(): Cannot convert to resource type
                    283: bool(false)
                    284: string(1) "1"
                    285: string(6) "string"
                    286: -- Iteration 17 --
                    287: string(6) "string"
                    288: 2: settype(): Cannot convert to resource type
                    289: bool(false)
                    290: string(2) "-1"
                    291: string(6) "string"
                    292: -- Iteration 18 --
                    293: string(6) "string"
                    294: 2: settype(): Cannot convert to resource type
                    295: bool(false)
                    296: string(3) "1e2"
                    297: string(6) "string"
                    298: -- Iteration 19 --
                    299: string(6) "string"
                    300: 2: settype(): Cannot convert to resource type
                    301: bool(false)
                    302: string(2) " 1"
                    303: string(6) "string"
                    304: -- Iteration 20 --
                    305: string(6) "string"
                    306: 2: settype(): Cannot convert to resource type
                    307: bool(false)
                    308: string(22) "2974394749328742328432"
                    309: string(6) "string"
                    310: -- Iteration 21 --
                    311: string(6) "string"
                    312: 2: settype(): Cannot convert to resource type
                    313: bool(false)
                    314: string(5) "-1e-2"
                    315: string(6) "string"
                    316: -- Iteration 22 --
                    317: string(6) "string"
                    318: 2: settype(): Cannot convert to resource type
                    319: bool(false)
                    320: string(1) "1"
                    321: string(6) "string"
                    322: -- Iteration 23 --
                    323: string(6) "string"
                    324: 2: settype(): Cannot convert to resource type
                    325: bool(false)
                    326: string(2) "-1"
                    327: string(6) "string"
                    328: -- Iteration 24 --
                    329: string(6) "string"
                    330: 2: settype(): Cannot convert to resource type
                    331: bool(false)
                    332: string(3) "1e2"
                    333: string(6) "string"
                    334: -- Iteration 25 --
                    335: string(6) "string"
                    336: 2: settype(): Cannot convert to resource type
                    337: bool(false)
                    338: string(2) " 1"
                    339: string(6) "string"
                    340: -- Iteration 26 --
                    341: string(6) "string"
                    342: 2: settype(): Cannot convert to resource type
                    343: bool(false)
                    344: string(22) "2974394749328742328432"
                    345: string(6) "string"
                    346: -- Iteration 27 --
                    347: string(6) "string"
                    348: 2: settype(): Cannot convert to resource type
                    349: bool(false)
                    350: string(5) "-1e-2"
                    351: string(6) "string"
                    352: -- Iteration 28 --
                    353: string(6) "string"
                    354: 2: settype(): Cannot convert to resource type
                    355: bool(false)
                    356: string(4) "0xff"
                    357: string(6) "string"
                    358: -- Iteration 29 --
                    359: string(6) "string"
                    360: 2: settype(): Cannot convert to resource type
                    361: bool(false)
                    362: string(4) "0x55"
                    363: string(6) "string"
                    364: -- Iteration 30 --
                    365: string(6) "string"
                    366: 2: settype(): Cannot convert to resource type
                    367: bool(false)
                    368: string(5) "0XA55"
                    369: string(6) "string"
                    370: -- Iteration 31 --
                    371: string(6) "string"
                    372: 2: settype(): Cannot convert to resource type
                    373: bool(false)
                    374: string(5) "0X123"
                    375: string(6) "string"
                    376: -- Iteration 32 --
                    377: string(6) "string"
                    378: 2: settype(): Cannot convert to resource type
                    379: bool(false)
                    380: string(4) "0123"
                    381: string(6) "string"
                    382: -- Iteration 33 --
                    383: string(6) "string"
                    384: 2: settype(): Cannot convert to resource type
                    385: bool(false)
                    386: string(4) "0123"
                    387: string(6) "string"
                    388: -- Iteration 34 --
                    389: string(6) "string"
                    390: 2: settype(): Cannot convert to resource type
                    391: bool(false)
                    392: string(5) "-0123"
                    393: string(6) "string"
                    394: -- Iteration 35 --
                    395: string(6) "string"
                    396: 2: settype(): Cannot convert to resource type
                    397: bool(false)
                    398: string(5) "+0123"
                    399: string(6) "string"
                    400: -- Iteration 36 --
                    401: string(6) "string"
                    402: 2: settype(): Cannot convert to resource type
                    403: bool(false)
                    404: string(5) "-0123"
                    405: string(6) "string"
                    406: -- Iteration 37 --
                    407: string(6) "string"
                    408: 2: settype(): Cannot convert to resource type
                    409: bool(false)
                    410: string(5) "+0123"
                    411: string(6) "string"
                    412: -- Iteration 38 --
                    413: string(6) "string"
                    414: 2: settype(): Cannot convert to resource type
                    415: bool(false)
                    416: string(8) "-0x80001"
                    417: string(6) "string"
                    418: -- Iteration 39 --
                    419: string(6) "string"
                    420: 2: settype(): Cannot convert to resource type
                    421: bool(false)
                    422: string(8) "+0x80001"
                    423: string(6) "string"
                    424: -- Iteration 40 --
                    425: string(6) "string"
                    426: 2: settype(): Cannot convert to resource type
                    427: bool(false)
                    428: string(10) "-0x80001.5"
                    429: string(6) "string"
                    430: -- Iteration 41 --
                    431: string(6) "string"
                    432: 2: settype(): Cannot convert to resource type
                    433: bool(false)
                    434: string(9) "0x80001.5"
                    435: string(6) "string"
                    436: -- Iteration 42 --
                    437: string(6) "string"
                    438: 2: settype(): Cannot convert to resource type
                    439: bool(false)
                    440: string(12) "@$%#$%^$%^&^"
                    441: string(6) "string"
                    442: -- Iteration 43 --
                    443: string(5) "array"
                    444: 2: settype(): Cannot convert to resource type
                    445: bool(false)
                    446: array(0) {
                    447: }
                    448: string(5) "array"
                    449: -- Iteration 44 --
                    450: string(5) "array"
                    451: 2: settype(): Cannot convert to resource type
                    452: bool(false)
                    453: array(1) {
                    454:   [0]=>
                    455:   NULL
                    456: }
                    457: string(5) "array"
                    458: -- Iteration 45 --
                    459: string(5) "array"
                    460: 2: settype(): Cannot convert to resource type
                    461: bool(false)
                    462: array(4) {
                    463:   [0]=>
                    464:   int(1)
                    465:   [1]=>
                    466:   int(2)
                    467:   [2]=>
                    468:   int(3)
                    469:   [3]=>
                    470:   int(4)
                    471: }
                    472: string(5) "array"
                    473: -- Iteration 46 --
                    474: string(5) "array"
                    475: 2: settype(): Cannot convert to resource type
                    476: bool(false)
                    477: array(4) {
                    478:   [1]=>
                    479:   string(3) "one"
                    480:   [2]=>
                    481:   string(3) "two"
                    482:   [3]=>
                    483:   string(5) "three"
                    484:   ["four"]=>
                    485:   int(4)
                    486: }
                    487: string(5) "array"
                    488: -- Iteration 47 --
                    489: string(5) "array"
                    490: 2: settype(): Cannot convert to resource type
                    491: bool(false)
                    492: array(3) {
                    493:   [0]=>
                    494:   float(1.5)
                    495:   [1]=>
                    496:   float(2.4)
                    497:   [2]=>
                    498:   float(6500000)
                    499: }
                    500: string(5) "array"
                    501: -- Iteration 48 --
                    502: string(6) "double"
                    503: 2: settype(): Cannot convert to resource type
                    504: bool(false)
                    505: float(-2147483648)
                    506: string(6) "double"
                    507: -- Iteration 49 --
                    508: string(7) "integer"
                    509: 2: settype(): Cannot convert to resource type
                    510: bool(false)
                    511: int(2147483647)
                    512: string(7) "integer"
                    513: -- Iteration 50 --
                    514: string(6) "double"
                    515: 2: settype(): Cannot convert to resource type
                    516: bool(false)
                    517: float(2147483649)
                    518: string(6) "double"
                    519: -- Iteration 51 --
                    520: string(6) "double"
                    521: 2: settype(): Cannot convert to resource type
                    522: bool(false)
                    523: float(1232147483649)
                    524: string(6) "double"
                    525: -- Iteration 52 --
                    526: string(7) "integer"
                    527: 2: settype(): Cannot convert to resource type
                    528: bool(false)
                    529: int(85)
                    530: string(7) "integer"
                    531: -- Iteration 53 --
                    532: string(6) "double"
                    533: 2: settype(): Cannot convert to resource type
                    534: bool(false)
                    535: float(1058513956921)
                    536: string(6) "double"
                    537: -- Iteration 54 --
                    538: string(7) "integer"
                    539: 2: settype(): Cannot convert to resource type
                    540: bool(false)
                    541: int(-21903)
                    542: string(7) "integer"
                    543: -- Iteration 55 --
                    544: string(7) "integer"
                    545: 2: settype(): Cannot convert to resource type
                    546: bool(false)
                    547: int(365)
                    548: string(7) "integer"
                    549: -- Iteration 56 --
                    550: string(7) "integer"
                    551: 2: settype(): Cannot convert to resource type
                    552: bool(false)
                    553: int(-365)
                    554: string(7) "integer"
                    555: -- Iteration 57 --
                    556: string(6) "double"
                    557: 2: settype(): Cannot convert to resource type
                    558: bool(false)
                    559: float(80561044571754)
                    560: string(6) "double"
                    561: -- Iteration 58 --
                    562: string(6) "double"
                    563: 2: settype(): Cannot convert to resource type
                    564: bool(false)
                    565: float(100000)
                    566: string(6) "double"
                    567: -- Iteration 59 --
                    568: string(6) "double"
                    569: 2: settype(): Cannot convert to resource type
                    570: bool(false)
                    571: float(-100000)
                    572: string(6) "double"
                    573: -- Iteration 60 --
                    574: string(6) "double"
                    575: 2: settype(): Cannot convert to resource type
                    576: bool(false)
                    577: float(100000)
                    578: string(6) "double"
                    579: -- Iteration 61 --
                    580: string(6) "double"
                    581: 2: settype(): Cannot convert to resource type
                    582: bool(false)
                    583: float(-100000)
                    584: string(6) "double"
                    585: -- Iteration 62 --
                    586: string(6) "double"
                    587: 2: settype(): Cannot convert to resource type
                    588: bool(false)
                    589: float(-1.5)
                    590: string(6) "double"
                    591: -- Iteration 63 --
                    592: string(6) "double"
                    593: 2: settype(): Cannot convert to resource type
                    594: bool(false)
                    595: float(0.5)
                    596: string(6) "double"
                    597: -- Iteration 64 --
                    598: string(6) "double"
                    599: 2: settype(): Cannot convert to resource type
                    600: bool(false)
                    601: float(-0.5)
                    602: string(6) "double"
                    603: -- Iteration 65 --
                    604: string(6) "double"
                    605: 2: settype(): Cannot convert to resource type
                    606: bool(false)
                    607: float(500000)
                    608: string(6) "double"
                    609: -- Iteration 66 --
                    610: string(6) "double"
                    611: 2: settype(): Cannot convert to resource type
                    612: bool(false)
                    613: float(-500000)
                    614: string(6) "double"
                    615: -- Iteration 67 --
                    616: string(6) "double"
                    617: 2: settype(): Cannot convert to resource type
                    618: bool(false)
                    619: float(-5.0E-7)
                    620: string(6) "double"
                    621: -- Iteration 68 --
                    622: string(6) "double"
                    623: 2: settype(): Cannot convert to resource type
                    624: bool(false)
                    625: float(500000)
                    626: string(6) "double"
                    627: -- Iteration 69 --
                    628: string(6) "double"
                    629: 2: settype(): Cannot convert to resource type
                    630: bool(false)
                    631: float(-500000)
                    632: string(6) "double"
                    633: -- Iteration 70 --
                    634: string(6) "double"
                    635: 2: settype(): Cannot convert to resource type
                    636: bool(false)
                    637: float(512000)
                    638: string(6) "double"
                    639: -- Iteration 71 --
                    640: string(6) "double"
                    641: 2: settype(): Cannot convert to resource type
                    642: bool(false)
                    643: float(-512000)
                    644: string(6) "double"
                    645: -- Iteration 72 --
                    646: string(6) "double"
                    647: 2: settype(): Cannot convert to resource type
                    648: bool(false)
                    649: float(5.12E-7)
                    650: string(6) "double"
                    651: -- Iteration 73 --
                    652: string(6) "double"
                    653: 2: settype(): Cannot convert to resource type
                    654: bool(false)
                    655: float(5.12E-7)
                    656: string(6) "double"
                    657: -- Iteration 74 --
                    658: string(6) "double"
                    659: 2: settype(): Cannot convert to resource type
                    660: bool(false)
                    661: float(512000)
                    662: string(6) "double"
                    663: -- Iteration 75 --
                    664: string(6) "double"
                    665: 2: settype(): Cannot convert to resource type
                    666: bool(false)
                    667: float(-512000)
                    668: string(6) "double"
                    669: -- Iteration 76 --
                    670: string(6) "object"
                    671: 2: settype(): Cannot convert to resource type
                    672: bool(false)
                    673: object(point)#1 (2) {
                    674:   ["x"]=>
                    675:   NULL
                    676:   ["y"]=>
                    677:   NULL
                    678: }
                    679: string(6) "object"
                    680: -- Iteration 77 --
                    681: string(6) "object"
                    682: 2: settype(): Cannot convert to resource type
                    683: bool(false)
                    684: object(point)#2 (2) {
                    685:   ["x"]=>
                    686:   float(2.5)
                    687:   ["y"]=>
                    688:   float(40.5)
                    689: }
                    690: string(6) "object"
                    691: -- Iteration 78 --
                    692: string(6) "object"
                    693: 2: settype(): Cannot convert to resource type
                    694: bool(false)
                    695: object(point)#3 (2) {
                    696:   ["x"]=>
                    697:   int(0)
                    698:   ["y"]=>
                    699:   int(0)
                    700: }
                    701: string(6) "object"
                    702: -- Iteration 79 --
                    703: string(4) "NULL"
                    704: 2: settype(): Cannot convert to resource type
                    705: bool(false)
                    706: NULL
                    707: string(4) "NULL"
                    708: -- Iteration 80 --
                    709: string(4) "NULL"
                    710: 2: settype(): Cannot convert to resource type
                    711: bool(false)
                    712: NULL
                    713: string(4) "NULL"
                    714: Done

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>