Annotation of embedaddon/php/ext/standard/tests/array/array_map_variation18.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Test array_map() function : usage variations - unexpected values for 'arr1' 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 non array values in place of $arr1
! 12: */
! 13:
! 14: echo "*** Testing array_map() : unexpected values for 'arr1' ***\n";
! 15:
! 16: function callback($a)
! 17: {
! 18: return $a;
! 19: }
! 20:
! 21: //get an unset array variable
! 22: $unset_var1 = array(1, 2);
! 23: unset ($unset_var1);
! 24:
! 25: // get an unset variable
! 26: $unset_var2 = 10;
! 27: unset ($unset_var2);
! 28:
! 29: // get a class
! 30: class classA
! 31: {
! 32: public function __toString() {
! 33: return "Class A object";
! 34: }
! 35: }
! 36:
! 37: // heredoc string
! 38: $heredoc = <<<EOT
! 39: hello world
! 40: EOT;
! 41:
! 42: // get a resource variable
! 43: $fp = fopen(__FILE__, "r");
! 44:
! 45: // different scalar/non-scalar values for array input
! 46: $unexpected_inputs = array(
! 47:
! 48: // int data
! 49: /*1*/ 0,
! 50: 1,
! 51: 12345,
! 52: -2345,
! 53:
! 54: // float data
! 55: /*5*/ 10.5,
! 56: -10.5,
! 57: 12.3456789000e10,
! 58: 12.3456789000E-10,
! 59: .5,
! 60:
! 61: // null data
! 62: /*10*/ NULL,
! 63: null,
! 64:
! 65: // boolean data
! 66: /*12*/ true,
! 67: false,
! 68: TRUE,
! 69: FALSE,
! 70:
! 71: // empty data
! 72: /*16*/ "",
! 73: '',
! 74:
! 75: // string data
! 76: /*18*/ "string",
! 77: 'string',
! 78: $heredoc,
! 79:
! 80: // object data
! 81: /*21*/ new classA(),
! 82:
! 83: // undefined data
! 84: /*22*/ @$undefined_var,
! 85:
! 86: // unset data
! 87: /*23*/ @$unset_var1,
! 88: @$unset_var2,
! 89:
! 90: // resource variable
! 91: /*25*/ $fp
! 92: );
! 93:
! 94: // loop through each element of $unexpected_inputs to check the behavior of array_map
! 95: for($count = 0; $count < count($unexpected_inputs); $count++) {
! 96: echo "-- Iteration ".($count + 1)." --\n";
! 97: var_dump( array_map('callback', $unexpected_inputs[$count]));
! 98: };
! 99:
! 100: fclose($fp);
! 101: echo "Done";
! 102: ?>
! 103: --EXPECTF--
! 104: *** Testing array_map() : unexpected values for 'arr1' ***
! 105: -- Iteration 1 --
! 106:
! 107: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 108: NULL
! 109: -- Iteration 2 --
! 110:
! 111: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 112: NULL
! 113: -- Iteration 3 --
! 114:
! 115: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 116: NULL
! 117: -- Iteration 4 --
! 118:
! 119: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 120: NULL
! 121: -- Iteration 5 --
! 122:
! 123: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 124: NULL
! 125: -- Iteration 6 --
! 126:
! 127: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 128: NULL
! 129: -- Iteration 7 --
! 130:
! 131: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 132: NULL
! 133: -- Iteration 8 --
! 134:
! 135: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 136: NULL
! 137: -- Iteration 9 --
! 138:
! 139: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 140: NULL
! 141: -- Iteration 10 --
! 142:
! 143: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 144: NULL
! 145: -- Iteration 11 --
! 146:
! 147: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 148: NULL
! 149: -- Iteration 12 --
! 150:
! 151: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 152: NULL
! 153: -- Iteration 13 --
! 154:
! 155: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 156: NULL
! 157: -- Iteration 14 --
! 158:
! 159: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 160: NULL
! 161: -- Iteration 15 --
! 162:
! 163: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 164: NULL
! 165: -- Iteration 16 --
! 166:
! 167: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 168: NULL
! 169: -- Iteration 17 --
! 170:
! 171: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 172: NULL
! 173: -- Iteration 18 --
! 174:
! 175: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 176: NULL
! 177: -- Iteration 19 --
! 178:
! 179: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 180: NULL
! 181: -- Iteration 20 --
! 182:
! 183: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 184: NULL
! 185: -- Iteration 21 --
! 186:
! 187: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 188: NULL
! 189: -- Iteration 22 --
! 190:
! 191: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 192: NULL
! 193: -- Iteration 23 --
! 194:
! 195: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 196: NULL
! 197: -- Iteration 24 --
! 198:
! 199: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 200: NULL
! 201: -- Iteration 25 --
! 202:
! 203: Warning: array_map(): Argument #2 should be an array in %s on line %d%d
! 204: NULL
! 205: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>