Annotation of embedaddon/php/ext/standard/tests/array/array_values_variation2.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: Test array_values() function : usage variations - arrays of different data types
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : array array_values(array $input)
                      6:  * Description: Return just the values from the input array 
                      7:  * Source code: ext/standard/array.c
                      8:  */
                      9: 
                     10: /*
                     11:  * Pass arrays of different data types as $input argument to array_values() to test behaviour
                     12:  */
                     13: 
                     14: echo "*** Testing array_values() : usage variations ***\n";
                     15: 
                     16: //get an unset variable
                     17: $unset_var = 10;
                     18: unset ($unset_var);
                     19: 
                     20: // get a class
                     21: class classA
                     22: {
                     23:   public function __toString() {
                     24:     return "Class A object";
                     25:   }
                     26: }
                     27: 
                     28: // heredoc string
                     29: $heredoc = <<<EOT
                     30: hello world
                     31: EOT;
                     32: 
                     33: // get a resource variable
                     34: $fp = fopen(__FILE__, "r");
                     35: 
                     36: // arrays of different data types to be passed as $input
                     37: $inputs = array(
                     38: 
                     39:        // int data
                     40: /*1*/  'int' => array(
                     41:           0,
                     42:        1,
                     43:        12345,
                     44:        -2345,
                     45:        ),
                     46: 
                     47:        // float data
                     48: /*2*/  'float' => array(
                     49:        10.5,
                     50:        -10.5,
                     51:        12.3456789000e10,
                     52:        12.3456789000E-10,
                     53:        .5,
                     54:        ),
                     55: 
                     56:        // null data
                     57: /*3*/ 'null' => array(
                     58:        NULL,
                     59:        null,
                     60:        ),
                     61: 
                     62:        // boolean data
                     63: /*4*/ 'bool' => array(
                     64:        true,
                     65:        false,
                     66:        TRUE,
                     67:        FALSE,
                     68:        ),
                     69:        
                     70:        // empty data
                     71: /*5*/ 'empty string' => array(
                     72:        "",
                     73:        '',
                     74:        ),
                     75:        
                     76: /*6*/ 'empty array' => array(
                     77:        ),
                     78: 
                     79:        // string data
                     80: /*7*/ 'string' => array(
                     81:        "string",
                     82:        'string',
                     83:        $heredoc,
                     84:        ),
                     85:        
                     86:        // object data
                     87: /*8*/ 'object' => array(
                     88:        new classA(),
                     89:        ),
                     90: 
                     91:        // undefined data
                     92: /*9*/ 'undefined' => array(
                     93:        @$undefined_var,
                     94:        ),
                     95: 
                     96:        // unset data
                     97: /*10*/ 'unset' => array(
                     98:        @$unset_var,
                     99:        ),
                    100: 
                    101:        // resource variable
                    102: /*11*/ 'resource' => array(
                    103:        $fp
                    104:        ),
                    105: );
                    106: 
                    107: // loop through each element of $inputs to check the behavior of array_values()
                    108: $iterator = 1;
                    109: foreach($inputs as $key => $input) {
                    110:   echo "\n-- Iteration $iterator: $key data --\n";
                    111:   var_dump( array_values($input) );
                    112:   $iterator++;
                    113: };
                    114: 
                    115: fclose($fp);
                    116: 
                    117: echo "Done";
                    118: ?>
                    119: 
                    120: --EXPECTF--
                    121: *** Testing array_values() : usage variations ***
                    122: 
                    123: -- Iteration 1: int data --
                    124: array(4) {
                    125:   [0]=>
                    126:   int(0)
                    127:   [1]=>
                    128:   int(1)
                    129:   [2]=>
                    130:   int(12345)
                    131:   [3]=>
                    132:   int(-2345)
                    133: }
                    134: 
                    135: -- Iteration 2: float data --
                    136: array(5) {
                    137:   [0]=>
                    138:   float(10.5)
                    139:   [1]=>
                    140:   float(-10.5)
                    141:   [2]=>
                    142:   float(123456789000)
                    143:   [3]=>
                    144:   float(1.23456789E-9)
                    145:   [4]=>
                    146:   float(0.5)
                    147: }
                    148: 
                    149: -- Iteration 3: null data --
                    150: array(2) {
                    151:   [0]=>
                    152:   NULL
                    153:   [1]=>
                    154:   NULL
                    155: }
                    156: 
                    157: -- Iteration 4: bool data --
                    158: array(4) {
                    159:   [0]=>
                    160:   bool(true)
                    161:   [1]=>
                    162:   bool(false)
                    163:   [2]=>
                    164:   bool(true)
                    165:   [3]=>
                    166:   bool(false)
                    167: }
                    168: 
                    169: -- Iteration 5: empty string data --
                    170: array(2) {
                    171:   [0]=>
                    172:   string(0) ""
                    173:   [1]=>
                    174:   string(0) ""
                    175: }
                    176: 
                    177: -- Iteration 6: empty array data --
                    178: array(0) {
                    179: }
                    180: 
                    181: -- Iteration 7: string data --
                    182: array(3) {
                    183:   [0]=>
                    184:   string(6) "string"
                    185:   [1]=>
                    186:   string(6) "string"
                    187:   [2]=>
                    188:   string(11) "hello world"
                    189: }
                    190: 
                    191: -- Iteration 8: object data --
                    192: array(1) {
                    193:   [0]=>
                    194:   object(classA)#%d (0) {
                    195:   }
                    196: }
                    197: 
                    198: -- Iteration 9: undefined data --
                    199: array(1) {
                    200:   [0]=>
                    201:   NULL
                    202: }
                    203: 
                    204: -- Iteration 10: unset data --
                    205: array(1) {
                    206:   [0]=>
                    207:   NULL
                    208: }
                    209: 
                    210: -- Iteration 11: resource data --
                    211: array(1) {
                    212:   [0]=>
                    213:   resource(%d) of type (stream)
                    214: }
                    215: Done

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