1--TEST-- 2Test 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*/ 12echo "*** 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; 19unset ($unset_var); 20 21// class definition for object variable 22class 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 88for($count = 0; $count < count($values); $count++) { 89 echo "-- Iteration ".($count + 1)." --"; 90 var_dump( array_filter($input, $values[$count]) ); 91}; 92 93// closing resource 94fclose($fp); 95 96echo "Done" 97?> 98--EXPECTF-- 99*** Testing array_filter() : usage variations - unexpected values for 'callback' function*** 100-- Iteration 1 -- 101Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 102NULL 103-- Iteration 2 -- 104Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 105NULL 106-- Iteration 3 -- 107Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 108NULL 109-- Iteration 4 -- 110Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 111NULL 112-- Iteration 5 -- 113Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 114NULL 115-- Iteration 6 -- 116Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 117NULL 118-- Iteration 7 -- 119Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 120NULL 121-- Iteration 8 -- 122Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 123NULL 124-- Iteration 9 -- 125Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 126NULL 127-- Iteration 10 -- 128Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 129NULL 130-- Iteration 11 -- 131Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 132NULL 133-- Iteration 12 -- 134Warning: array_filter() expects parameter 2 to be a valid callback, array must have exactly two members in %s on line %d 135NULL 136-- Iteration 13 -- 137Warning: 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 138NULL 139-- Iteration 14 -- 140Warning: 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 141NULL 142-- Iteration 15 -- 143Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 144NULL 145-- Iteration 16 -- 146Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 147NULL 148-- Iteration 17 -- 149Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 150NULL 151-- Iteration 18 -- 152Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 153NULL 154-- Iteration 19 -- 155Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 156NULL 157-- Iteration 20 -- 158Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 159NULL 160-- Iteration 21 -- 161Warning: array_filter() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d 162NULL 163-- Iteration 22 -- 164Warning: array_filter() expects parameter 2 to be a valid callback, function '' not found or invalid function name in %s on line %d 165NULL 166-- Iteration 23 -- 167Warning: array_filter() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d 168NULL 169-- Iteration 24 -- 170Warning: array_filter() expects parameter 2 to be a valid callback, function 'string' not found or invalid function name in %s on line %d 171NULL 172-- Iteration 25 -- 173Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 174NULL 175-- Iteration 26 -- 176Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 177NULL 178-- Iteration 27 -- 179Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 180NULL 181-- Iteration 28 -- 182Warning: array_filter() expects parameter 2 to be a valid callback, no array or string given in %s on line %d 183NULL 184Done 185