Annotation of embedaddon/php/ext/standard/tests/general_functions/type.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: gettype(), settype() and friends
                      3: --FILE--
                      4: <?php
                      5: 
                      6: function foo($errno, $errstr, $errfile, $errline) {
                      7:        var_dump($errstr);
                      8: }
                      9: 
                     10: set_error_handler("foo");
                     11: 
                     12: $fp = fopen(__FILE__, "r");
                     13: fclose($fp);
                     14: $fp1 = fopen(__FILE__, "r");
                     15: 
                     16: $var1 = "another string";
                     17: $var2 = array(2,3,4);
                     18: 
                     19: $array = array(
                     20:        array(1,2,3),
                     21:        $var1,
                     22:        $var2,
                     23:        1,
                     24:        2.0,
                     25:        NULL,
                     26:        false,
                     27:        "some string",
                     28:        $fp,
                     29:        $fp1,
                     30:        new stdclass,
                     31: );
                     32: 
                     33: $types = array(
                     34:        "null",
                     35:        "integer",
                     36:        "double",
                     37:        "boolean",
                     38:        "resource",
                     39:        "array",
                     40:        "object",
                     41:        "string"
                     42:        );
                     43: 
                     44: foreach ($array as $var) {
                     45:        var_dump(gettype($var));
                     46: }
                     47: 
                     48: foreach ($types as $type) {
                     49:        foreach ($array as $var) {
                     50:                var_dump(settype($var, $type));
                     51:                var_dump($var);
                     52:        }
                     53: }
                     54: 
                     55: echo "Done\n";
                     56: ?>
                     57: --EXPECTF--    
                     58: string(5) "array"
                     59: string(6) "string"
                     60: string(5) "array"
                     61: string(7) "integer"
                     62: string(6) "double"
                     63: string(4) "NULL"
                     64: string(7) "boolean"
                     65: string(6) "string"
                     66: string(12) "unknown type"
                     67: string(8) "resource"
                     68: string(6) "object"
                     69: bool(true)
                     70: NULL
                     71: bool(true)
                     72: NULL
                     73: bool(true)
                     74: NULL
                     75: bool(true)
                     76: NULL
                     77: bool(true)
                     78: NULL
                     79: bool(true)
                     80: NULL
                     81: bool(true)
                     82: NULL
                     83: bool(true)
                     84: NULL
                     85: bool(true)
                     86: NULL
                     87: bool(true)
                     88: NULL
                     89: bool(true)
                     90: NULL
                     91: bool(true)
                     92: int(1)
                     93: bool(true)
                     94: int(0)
                     95: bool(true)
                     96: int(1)
                     97: bool(true)
                     98: int(1)
                     99: bool(true)
                    100: int(2)
                    101: bool(true)
                    102: int(0)
                    103: bool(true)
                    104: int(0)
                    105: bool(true)
                    106: int(0)
                    107: bool(true)
                    108: int(5)
                    109: bool(true)
                    110: int(6)
                    111: string(54) "Object of class stdClass could not be converted to int"
                    112: bool(true)
                    113: int(%d)
                    114: bool(true)
                    115: float(1)
                    116: bool(true)
                    117: float(0)
                    118: bool(true)
                    119: float(1)
                    120: bool(true)
                    121: float(1)
                    122: bool(true)
                    123: float(2)
                    124: bool(true)
                    125: float(0)
                    126: bool(true)
                    127: float(0)
                    128: bool(true)
                    129: float(0)
                    130: bool(true)
                    131: float(5)
                    132: bool(true)
                    133: float(6)
                    134: string(57) "Object of class stdClass could not be converted to double"
                    135: bool(true)
                    136: float(%d)
                    137: bool(true)
                    138: bool(true)
                    139: bool(true)
                    140: bool(true)
                    141: bool(true)
                    142: bool(true)
                    143: bool(true)
                    144: bool(true)
                    145: bool(true)
                    146: bool(true)
                    147: bool(true)
                    148: bool(false)
                    149: bool(true)
                    150: bool(false)
                    151: bool(true)
                    152: bool(true)
                    153: bool(true)
                    154: bool(true)
                    155: bool(true)
                    156: bool(true)
                    157: bool(true)
                    158: bool(true)
                    159: string(42) "settype(): Cannot convert to resource type"
                    160: bool(false)
                    161: array(3) {
                    162:   [0]=>
                    163:   int(1)
                    164:   [1]=>
                    165:   int(2)
                    166:   [2]=>
                    167:   int(3)
                    168: }
                    169: string(42) "settype(): Cannot convert to resource type"
                    170: bool(false)
                    171: string(14) "another string"
                    172: string(42) "settype(): Cannot convert to resource type"
                    173: bool(false)
                    174: array(3) {
                    175:   [0]=>
                    176:   int(2)
                    177:   [1]=>
                    178:   int(3)
                    179:   [2]=>
                    180:   int(4)
                    181: }
                    182: string(42) "settype(): Cannot convert to resource type"
                    183: bool(false)
                    184: int(1)
                    185: string(42) "settype(): Cannot convert to resource type"
                    186: bool(false)
                    187: float(2)
                    188: string(42) "settype(): Cannot convert to resource type"
                    189: bool(false)
                    190: NULL
                    191: string(42) "settype(): Cannot convert to resource type"
                    192: bool(false)
                    193: bool(false)
                    194: string(42) "settype(): Cannot convert to resource type"
                    195: bool(false)
                    196: string(11) "some string"
                    197: string(42) "settype(): Cannot convert to resource type"
                    198: bool(false)
                    199: resource(%d) of type (Unknown)
                    200: string(42) "settype(): Cannot convert to resource type"
                    201: bool(false)
                    202: resource(%d) of type (stream)
                    203: string(42) "settype(): Cannot convert to resource type"
                    204: bool(false)
                    205: object(stdClass)#%d (0) {
                    206: }
                    207: bool(true)
                    208: array(3) {
                    209:   [0]=>
                    210:   int(1)
                    211:   [1]=>
                    212:   int(2)
                    213:   [2]=>
                    214:   int(3)
                    215: }
                    216: bool(true)
                    217: array(1) {
                    218:   [0]=>
                    219:   string(14) "another string"
                    220: }
                    221: bool(true)
                    222: array(3) {
                    223:   [0]=>
                    224:   int(2)
                    225:   [1]=>
                    226:   int(3)
                    227:   [2]=>
                    228:   int(4)
                    229: }
                    230: bool(true)
                    231: array(1) {
                    232:   [0]=>
                    233:   int(1)
                    234: }
                    235: bool(true)
                    236: array(1) {
                    237:   [0]=>
                    238:   float(2)
                    239: }
                    240: bool(true)
                    241: array(0) {
                    242: }
                    243: bool(true)
                    244: array(1) {
                    245:   [0]=>
                    246:   bool(false)
                    247: }
                    248: bool(true)
                    249: array(1) {
                    250:   [0]=>
                    251:   string(11) "some string"
                    252: }
                    253: bool(true)
                    254: array(1) {
                    255:   [0]=>
                    256:   resource(%d) of type (Unknown)
                    257: }
                    258: bool(true)
                    259: array(1) {
                    260:   [0]=>
                    261:   resource(%d) of type (stream)
                    262: }
                    263: bool(true)
                    264: array(0) {
                    265: }
                    266: bool(true)
                    267: object(stdClass)#%d (3) {
                    268:   [0]=>
                    269:   int(1)
                    270:   [1]=>
                    271:   int(2)
                    272:   [2]=>
                    273:   int(3)
                    274: }
                    275: bool(true)
                    276: object(stdClass)#%d (1) {
                    277:   ["scalar"]=>
                    278:   string(14) "another string"
                    279: }
                    280: bool(true)
                    281: object(stdClass)#%d (3) {
                    282:   [0]=>
                    283:   int(2)
                    284:   [1]=>
                    285:   int(3)
                    286:   [2]=>
                    287:   int(4)
                    288: }
                    289: bool(true)
                    290: object(stdClass)#%d (1) {
                    291:   ["scalar"]=>
                    292:   int(1)
                    293: }
                    294: bool(true)
                    295: object(stdClass)#%d (1) {
                    296:   ["scalar"]=>
                    297:   float(2)
                    298: }
                    299: bool(true)
                    300: object(stdClass)#%d (0) {
                    301: }
                    302: bool(true)
                    303: object(stdClass)#%d (1) {
                    304:   ["scalar"]=>
                    305:   bool(false)
                    306: }
                    307: bool(true)
                    308: object(stdClass)#%d (1) {
                    309:   ["scalar"]=>
                    310:   string(11) "some string"
                    311: }
                    312: bool(true)
                    313: object(stdClass)#%d (1) {
                    314:   ["scalar"]=>
                    315:   resource(%d) of type (Unknown)
                    316: }
                    317: bool(true)
                    318: object(stdClass)#%d (1) {
                    319:   ["scalar"]=>
                    320:   resource(%d) of type (stream)
                    321: }
                    322: bool(true)
                    323: object(stdClass)#%d (0) {
                    324: }
                    325: string(26) "Array to string conversion"
                    326: bool(true)
                    327: string(5) "Array"
                    328: bool(true)
                    329: string(14) "another string"
                    330: string(26) "Array to string conversion"
                    331: bool(true)
                    332: string(5) "Array"
                    333: bool(true)
                    334: string(1) "1"
                    335: bool(true)
                    336: string(1) "2"
                    337: bool(true)
                    338: string(0) ""
                    339: bool(true)
                    340: string(0) ""
                    341: bool(true)
                    342: string(11) "some string"
                    343: bool(true)
                    344: string(14) "Resource id #%d"
                    345: bool(true)
                    346: string(14) "Resource id #%d"
                    347: string(57) "Object of class stdClass could not be converted to string"
                    348: string(45) "Object of class stdClass to string conversion"
                    349: bool(true)
                    350: string(6) "Object"
                    351: Done

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