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

1.1       misho       1: --TEST--
                      2: Test key() function : usage variations
                      3: --FILE--
                      4: <?php
                      5: /* Prototype  : mixed key(array $array_arg)
                      6:  * Description: Return the key of the element currently pointed to by the internal array pointer 
                      7:  * Source code: ext/standard/array.c
                      8:  */
                      9: 
                     10: /*
                     11:  * Pass arrays where keys are different data types as $array_arg to key() to test behaviour
                     12:  */
                     13: 
                     14: echo "*** Testing key() : usage variations ***\n";
                     15: 
                     16: //get an unset variable
                     17: $unset_var = 10;
                     18: unset ($unset_var);
                     19: 
                     20: // heredoc string
                     21: $heredoc = <<<EOT
                     22: hello world
                     23: EOT;
                     24: 
                     25: // unexpected values to be passed as $array_arg
                     26: $inputs = array(
                     27: 
                     28:        // int data
                     29: /*1*/  'int' => array(
                     30:        0 => 'zero',
                     31:        1 => 'one',
                     32:        12345 => 'positive',
                     33:        -2345 => 'negative',
                     34:        ),
                     35: 
                     36:        // float data
                     37: /*2*/  'float' => array(
                     38:        10.5 => 'positive',
                     39:        -10.5 => 'negative',
                     40:        .5 => 'half',
                     41:        ),
                     42:        
                     43: /*3*/  'extreme floats' => array(
                     44:        12.3456789000e6 => 'large',
                     45:        12.3456789000E-10 => 'small',
                     46:        ),
                     47: 
                     48:        // null data
                     49: /*4*/ 'null uppercase' => array(
                     50:        NULL => 'null 1',
                     51:        ), 
                     52:        
                     53: /*5*/  'null lowercase' => array(
                     54:        null => 'null 2',
                     55:        ),
                     56: 
                     57:        // boolean data
                     58: /*6*/ 'bool lowercase' => array(
                     59:        true => 'lowert',
                     60:        false => 'lowerf',
                     61:        ),
                     62:        
                     63: /*7*/  'bool uppercase' => array(
                     64:        TRUE => 'uppert',
                     65:        FALSE => 'upperf',
                     66:        ),
                     67:        
                     68:        // empty data
                     69: /*8*/ 'empty double quotes' => array(
                     70:        "" => 'emptyd',
                     71:        ),
                     72:        
                     73: /*9*/  'empty single quotes' => array(
                     74:        '' => 'emptys',
                     75:        ),
                     76: 
                     77:        // string data
                     78: /*10*/ 'string' => array(
                     79:        "stringd" => 'stringd',
                     80:        'strings' => 'strings',
                     81:        $heredoc => 'stringh',
                     82:        ),
                     83: 
                     84:        // undefined data
                     85: /*11*/ 'undefined' => array(
                     86:        @$undefined_var => 'undefined',
                     87:        ),
                     88: 
                     89:        // unset data
                     90: /*12*/ 'unset' => array(
                     91:        @$unset_var => 'unset',
                     92:        ),
                     93: );
                     94: 
                     95: // loop through each element of $inputs to check the behavior of key()
                     96: $iterator = 1;
                     97: foreach($inputs as $key => $input) {
                     98:   echo "\n-- Iteration $iterator : $key data --\n";
                     99:   while (key($input) !== NULL) {
                    100:        var_dump(key($input));
                    101:        next($input);
                    102:   }
                    103:   $iterator++;
                    104: };
                    105: ?>
                    106: ===DONE===
                    107: --EXPECTF--
                    108: *** Testing key() : usage variations ***
                    109: 
                    110: -- Iteration 1 : int data --
                    111: int(0)
                    112: int(1)
                    113: int(12345)
                    114: int(-2345)
                    115: 
                    116: -- Iteration 2 : float data --
                    117: int(10)
                    118: int(-10)
                    119: int(0)
                    120: 
                    121: -- Iteration 3 : extreme floats data --
                    122: int(12345678)
                    123: int(0)
                    124: 
                    125: -- Iteration 4 : null uppercase data --
                    126: string(0) ""
                    127: 
                    128: -- Iteration 5 : null lowercase data --
                    129: string(0) ""
                    130: 
                    131: -- Iteration 6 : bool lowercase data --
                    132: int(1)
                    133: int(0)
                    134: 
                    135: -- Iteration 7 : bool uppercase data --
                    136: int(1)
                    137: int(0)
                    138: 
                    139: -- Iteration 8 : empty double quotes data --
                    140: string(0) ""
                    141: 
                    142: -- Iteration 9 : empty single quotes data --
                    143: string(0) ""
                    144: 
                    145: -- Iteration 10 : string data --
                    146: string(7) "stringd"
                    147: string(7) "strings"
                    148: string(11) "hello world"
                    149: 
                    150: -- Iteration 11 : undefined data --
                    151: string(0) ""
                    152: 
                    153: -- Iteration 12 : unset data --
                    154: string(0) ""
                    155: ===DONE===

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