1--TEST--
2Test array_map() function : usage variations - unexpected values for 'callback' argument
3--FILE--
4<?php
5/*
6 * Test array_map() by passing different scalar/nonscalar values in place of $callback
7 */
8
9echo "*** Testing array_map() : unexpected values for 'callback' argument ***\n";
10
11$arr1 = array(1, 2, 3);
12
13// get a class
14class classA
15{
16  public function __toString() {
17    return "Class A object";
18  }
19}
20
21// get a resource variable
22$fp = fopen(__FILE__, "r");
23
24// unexpected values to be passed to $input argument
25$unexpected_callbacks = array(
26
27       // int data
28/*1*/  0,
29       1,
30       12345,
31       -2345,
32
33       // float data
34/*5*/  10.5,
35       -10.5,
36       12.3456789000e10,
37       12.3456789000E-10,
38       .5,
39
40       // boolean data
41/*10*/ true,
42       false,
43       TRUE,
44       FALSE,
45
46       // empty data
47/*14*/ "",
48       '',
49
50       // array data
51/*16*/ array(),
52       array(1, 2),
53       array(1, array(2)),
54
55       // object data
56/*19*/ new classA(),
57
58       // resource variable
59/*20*/ $fp
60);
61
62// loop through each element of $inputs to check the behavior of array_map
63for($count = 0; $count < count($unexpected_callbacks); $count++) {
64    echo "\n-- Iteration ".($count + 1)." --\n";
65    try {
66        var_dump( array_map($unexpected_callbacks[$count], $arr1));
67    } catch (TypeError $e) {
68        echo $e->getMessage(), "\n";
69    }
70};
71
72fclose($fp);
73echo "Done";
74?>
75--EXPECT--
76*** Testing array_map() : unexpected values for 'callback' argument ***
77
78-- Iteration 1 --
79array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
80
81-- Iteration 2 --
82array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
83
84-- Iteration 3 --
85array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
86
87-- Iteration 4 --
88array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
89
90-- Iteration 5 --
91array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
92
93-- Iteration 6 --
94array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
95
96-- Iteration 7 --
97array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
98
99-- Iteration 8 --
100array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
101
102-- Iteration 9 --
103array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
104
105-- Iteration 10 --
106array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
107
108-- Iteration 11 --
109array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
110
111-- Iteration 12 --
112array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
113
114-- Iteration 13 --
115array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
116
117-- Iteration 14 --
118array_map(): Argument #1 ($callback) must be a valid callback or null, function "" not found or invalid function name
119
120-- Iteration 15 --
121array_map(): Argument #1 ($callback) must be a valid callback or null, function "" not found or invalid function name
122
123-- Iteration 16 --
124array_map(): Argument #1 ($callback) must be a valid callback or null, array callback must have exactly two members
125
126-- Iteration 17 --
127array_map(): Argument #1 ($callback) must be a valid callback or null, first array member is not a valid class name or object
128
129-- Iteration 18 --
130array_map(): Argument #1 ($callback) must be a valid callback or null, first array member is not a valid class name or object
131
132-- Iteration 19 --
133array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
134
135-- Iteration 20 --
136array_map(): Argument #1 ($callback) must be a valid callback or null, no array or string given
137Done
138