Return to array_map_variation17.phpt CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / php / ext / standard / tests / array |
1.1 misho 1: --TEST-- 2: Test array_map() function : usage variations - unexpected values for 'callback' argument 3: --FILE-- 4: <?php 5: /* Prototype : array array_map ( callback $callback , array $arr1 [, array $... ] ) 6: * Description: Applies the callback to the elements of the given arrays 7: * Source code: ext/standard/array.c 8: */ 9: 10: /* 11: * Test array_map() by passing different scalar/nonscalar values in place of $callback 12: */ 13: 14: echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n"; 15: 16: $arr1 = array(1, 2, 3); 17: 18: // get a class 19: class classA 20: { 21: public function __toString() { 22: return "Class A object"; 23: } 24: } 25: 26: // get a resource variable 27: $fp = fopen(__FILE__, "r"); 28: 29: // unexpected values to be passed to $input argument 30: $unexpected_callbacks = array( 31: 32: // int data 33: /*1*/ 0, 34: 1, 35: 12345, 36: -2345, 37: 38: // float data 39: /*5*/ 10.5, 40: -10.5, 41: 12.3456789000e10, 42: 12.3456789000E-10, 43: .5, 44: 45: // boolean data 46: /*10*/ true, 47: false, 48: TRUE, 49: FALSE, 50: 51: // empty data 52: /*14*/ "", 53: '', 54: 55: // array data 56: /*16*/ array(), 57: array(1, 2), 58: array(1, array(2)), 59: 60: // object data 61: /*19*/ new classA(), 62: 63: // resource variable 64: /*20*/ $fp 65: ); 66: 67: // loop through each element of $inputs to check the behavior of array_map 68: for($count = 0; $count < count($unexpected_callbacks); $count++) { 69: echo "\n-- Iteration ".($count + 1)." --"; 70: var_dump( array_map($unexpected_callbacks[$count], $arr1)); 71: }; 72: 73: fclose($fp); 74: echo "Done"; 75: ?> 76: --EXPECTF-- 77: *** Testing array_map() : unexpected values for 'callback' argument *** 78: 79: -- Iteration 1 -- 80: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 81: NULL 82: 83: -- Iteration 2 -- 84: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 85: NULL 86: 87: -- Iteration 3 -- 88: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 89: NULL 90: 91: -- Iteration 4 -- 92: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 93: NULL 94: 95: -- Iteration 5 -- 96: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 97: NULL 98: 99: -- Iteration 6 -- 100: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 101: NULL 102: 103: -- Iteration 7 -- 104: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 105: NULL 106: 107: -- Iteration 8 -- 108: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 109: NULL 110: 111: -- Iteration 9 -- 112: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 113: NULL 114: 115: -- Iteration 10 -- 116: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 117: NULL 118: 119: -- Iteration 11 -- 120: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 121: NULL 122: 123: -- Iteration 12 -- 124: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 125: NULL 126: 127: -- Iteration 13 -- 128: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 129: NULL 130: 131: -- Iteration 14 -- 132: Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d 133: NULL 134: 135: -- Iteration 15 -- 136: Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d 137: NULL 138: 139: -- Iteration 16 -- 140: Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d 141: NULL 142: 143: -- Iteration 17 -- 144: Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d 145: NULL 146: 147: -- Iteration 18 -- 148: Warning: array_map() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in %s on line %d 149: NULL 150: 151: -- Iteration 19 -- 152: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 153: NULL 154: 155: -- Iteration 20 -- 156: Warning: array_map() expects parameter 1 to be a valid callback, no array or string given in %s on line %d 157: NULL 158: Done