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

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

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