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

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

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