1--TEST--
2Test array_map() function : usage variations - references
3--FILE--
4<?php
5
6/* Prototype  : array array_map(mixed callback, array input1 [, array input2 ,...])
7 * Description: Applies the callback to the elements in given arrays.
8 * Source code: ext/standard/array.c
9*/
10
11echo "*** Testing array_map() : references ***\n";
12$arr = array("k1" => "v1","k2"=>"v2");
13$arr[]=&$arr["k1"];
14$arr[]=&$arr;
15function cb1 ($a) {var_dump ($a);return array ($a);};
16function cb2 (&$a) {var_dump ($a);return array (&$a);};
17var_dump( array_map("cb1", $arr));
18var_dump( array_map("cb2", $arr,$arr));
19var_dump( array_map(null,  $arr));
20var_dump( array_map(null, $arr, $arr));
21
22// break cycles
23$arr[0] = null;
24$arr[1] = null;
25
26echo "Done";
27?>
28
29--EXPECT--
30*** Testing array_map() : references ***
31string(2) "v1"
32string(2) "v2"
33string(2) "v1"
34array(4) {
35  ["k1"]=>
36  &string(2) "v1"
37  ["k2"]=>
38  string(2) "v2"
39  [0]=>
40  &string(2) "v1"
41  [1]=>
42  &array(4) {
43    ["k1"]=>
44    &string(2) "v1"
45    ["k2"]=>
46    string(2) "v2"
47    [0]=>
48    &string(2) "v1"
49    [1]=>
50    *RECURSION*
51  }
52}
53array(4) {
54  ["k1"]=>
55  array(1) {
56    [0]=>
57    string(2) "v1"
58  }
59  ["k2"]=>
60  array(1) {
61    [0]=>
62    string(2) "v2"
63  }
64  [0]=>
65  array(1) {
66    [0]=>
67    string(2) "v1"
68  }
69  [1]=>
70  array(1) {
71    [0]=>
72    array(4) {
73      ["k1"]=>
74      &string(2) "v1"
75      ["k2"]=>
76      string(2) "v2"
77      [0]=>
78      &string(2) "v1"
79      [1]=>
80      &array(4) {
81        ["k1"]=>
82        &string(2) "v1"
83        ["k2"]=>
84        string(2) "v2"
85        [0]=>
86        &string(2) "v1"
87        [1]=>
88        *RECURSION*
89      }
90    }
91  }
92}
93string(2) "v1"
94string(2) "v2"
95string(2) "v1"
96array(4) {
97  ["k1"]=>
98  &string(2) "v1"
99  ["k2"]=>
100  string(2) "v2"
101  [0]=>
102  &string(2) "v1"
103  [1]=>
104  &array(4) {
105    ["k1"]=>
106    &string(2) "v1"
107    ["k2"]=>
108    string(2) "v2"
109    [0]=>
110    &string(2) "v1"
111    [1]=>
112    *RECURSION*
113  }
114}
115array(4) {
116  [0]=>
117  array(1) {
118    [0]=>
119    &string(2) "v1"
120  }
121  [1]=>
122  array(1) {
123    [0]=>
124    string(2) "v2"
125  }
126  [2]=>
127  array(1) {
128    [0]=>
129    &string(2) "v1"
130  }
131  [3]=>
132  array(1) {
133    [0]=>
134    &array(4) {
135      ["k1"]=>
136      &string(2) "v1"
137      ["k2"]=>
138      string(2) "v2"
139      [0]=>
140      &string(2) "v1"
141      [1]=>
142      *RECURSION*
143    }
144  }
145}
146array(4) {
147  ["k1"]=>
148  &string(2) "v1"
149  ["k2"]=>
150  string(2) "v2"
151  [0]=>
152  &string(2) "v1"
153  [1]=>
154  &array(4) {
155    ["k1"]=>
156    &string(2) "v1"
157    ["k2"]=>
158    string(2) "v2"
159    [0]=>
160    &string(2) "v1"
161    [1]=>
162    *RECURSION*
163  }
164}
165array(4) {
166  [0]=>
167  array(2) {
168    [0]=>
169    &string(2) "v1"
170    [1]=>
171    &string(2) "v1"
172  }
173  [1]=>
174  array(2) {
175    [0]=>
176    string(2) "v2"
177    [1]=>
178    string(2) "v2"
179  }
180  [2]=>
181  array(2) {
182    [0]=>
183    &string(2) "v1"
184    [1]=>
185    &string(2) "v1"
186  }
187  [3]=>
188  array(2) {
189    [0]=>
190    &array(4) {
191      ["k1"]=>
192      &string(2) "v1"
193      ["k2"]=>
194      string(2) "v2"
195      [0]=>
196      &string(2) "v1"
197      [1]=>
198      *RECURSION*
199    }
200    [1]=>
201    &array(4) {
202      ["k1"]=>
203      &string(2) "v1"
204      ["k2"]=>
205      string(2) "v2"
206      [0]=>
207      &string(2) "v1"
208      [1]=>
209      *RECURSION*
210    }
211  }
212}
213Done
214