Annotation of embedaddon/php/ext/standard/tests/array/array_map_variation14.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test array_map() function : usage variations - null value 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 null values for $callback argument and testing whether shortest
12: * array will be extended with empty elements
13: */
14:
15: echo "*** Testing array_map() : null value for 'callback' argument ***\n";
16:
17: // arrays to be passed as arguments
18: $arr1 = array(1, 2);
19: $arr2 = array("one", "two");
20: $arr3 = array(1.1, 2.2);
21:
22: // get an unset variable
23: $unset_var = 10;
24: unset ($unset_var);
25:
26: /* calling array_map() with null callback */
27:
28: echo "-- with null --\n";
29: var_dump( array_map(null, $arr1, $arr2, $arr3) );
30: var_dump( array_map(NULL, $arr1, $arr2, $arr3) );
31:
32: echo "-- with unset variable --\n";
33: var_dump( array_map(@$unset_var, $arr1, $arr2, $arr3) );
34:
35: echo "-- with undefined variable --\n";
36: var_dump( array_map(@$undefined_var, $arr1) );
37:
38: echo "-- with empty string --\n";
39: var_dump( array_map("", $arr1, $arr2) );
40:
41: echo "-- with empty array --\n";
42: var_dump( array_map(array(), $arr1, $arr2) );
43:
44: echo "Done";
45: ?>
46: --EXPECTF--
47: *** Testing array_map() : null value for 'callback' argument ***
48: -- with null --
49: array(2) {
50: [0]=>
51: array(3) {
52: [0]=>
53: int(1)
54: [1]=>
55: string(3) "one"
56: [2]=>
57: float(1.1)
58: }
59: [1]=>
60: array(3) {
61: [0]=>
62: int(2)
63: [1]=>
64: string(3) "two"
65: [2]=>
66: float(2.2)
67: }
68: }
69: array(2) {
70: [0]=>
71: array(3) {
72: [0]=>
73: int(1)
74: [1]=>
75: string(3) "one"
76: [2]=>
77: float(1.1)
78: }
79: [1]=>
80: array(3) {
81: [0]=>
82: int(2)
83: [1]=>
84: string(3) "two"
85: [2]=>
86: float(2.2)
87: }
88: }
89: -- with unset variable --
90: array(2) {
91: [0]=>
92: array(3) {
93: [0]=>
94: int(1)
95: [1]=>
96: string(3) "one"
97: [2]=>
98: float(1.1)
99: }
100: [1]=>
101: array(3) {
102: [0]=>
103: int(2)
104: [1]=>
105: string(3) "two"
106: [2]=>
107: float(2.2)
108: }
109: }
110: -- with undefined variable --
111: array(2) {
112: [0]=>
113: int(1)
114: [1]=>
115: int(2)
116: }
117: -- with empty string --
118:
119: Warning: array_map() expects parameter 1 to be a valid callback, function '' not found or invalid function name in %s on line %d
120: NULL
121: -- with empty array --
122:
123: Warning: array_map() expects parameter 1 to be a valid callback, array must have exactly two members in %s on line %d
124: NULL
125: Done
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>