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--EXPECT--
29*** Testing array_map() : references ***
30string(2) "v1"
31string(2) "v2"
32string(2) "v1"
33array(4) {
34  ["k1"]=>
35  &string(2) "v1"
36  ["k2"]=>
37  string(2) "v2"
38  [0]=>
39  &string(2) "v1"
40  [1]=>
41  &array(4) {
42    ["k1"]=>
43    &string(2) "v1"
44    ["k2"]=>
45    string(2) "v2"
46    [0]=>
47    &string(2) "v1"
48    [1]=>
49    *RECURSION*
50  }
51}
52array(4) {
53  ["k1"]=>
54  array(1) {
55    [0]=>
56    string(2) "v1"
57  }
58  ["k2"]=>
59  array(1) {
60    [0]=>
61    string(2) "v2"
62  }
63  [0]=>
64  array(1) {
65    [0]=>
66    string(2) "v1"
67  }
68  [1]=>
69  array(1) {
70    [0]=>
71    array(4) {
72      ["k1"]=>
73      &string(2) "v1"
74      ["k2"]=>
75      string(2) "v2"
76      [0]=>
77      &string(2) "v1"
78      [1]=>
79      *RECURSION*
80    }
81  }
82}
83string(2) "v1"
84string(2) "v2"
85string(2) "v1"
86array(4) {
87  ["k1"]=>
88  &string(2) "v1"
89  ["k2"]=>
90  string(2) "v2"
91  [0]=>
92  &string(2) "v1"
93  [1]=>
94  &array(4) {
95    ["k1"]=>
96    &string(2) "v1"
97    ["k2"]=>
98    string(2) "v2"
99    [0]=>
100    &string(2) "v1"
101    [1]=>
102    *RECURSION*
103  }
104}
105array(4) {
106  [0]=>
107  array(1) {
108    [0]=>
109    &string(2) "v1"
110  }
111  [1]=>
112  array(1) {
113    [0]=>
114    string(2) "v2"
115  }
116  [2]=>
117  array(1) {
118    [0]=>
119    &string(2) "v1"
120  }
121  [3]=>
122  array(1) {
123    [0]=>
124    &array(4) {
125      ["k1"]=>
126      &string(2) "v1"
127      ["k2"]=>
128      string(2) "v2"
129      [0]=>
130      &string(2) "v1"
131      [1]=>
132      *RECURSION*
133    }
134  }
135}
136array(4) {
137  ["k1"]=>
138  &string(2) "v1"
139  ["k2"]=>
140  string(2) "v2"
141  [0]=>
142  &string(2) "v1"
143  [1]=>
144  &array(4) {
145    ["k1"]=>
146    &string(2) "v1"
147    ["k2"]=>
148    string(2) "v2"
149    [0]=>
150    &string(2) "v1"
151    [1]=>
152    *RECURSION*
153  }
154}
155array(4) {
156  [0]=>
157  array(2) {
158    [0]=>
159    &string(2) "v1"
160    [1]=>
161    &string(2) "v1"
162  }
163  [1]=>
164  array(2) {
165    [0]=>
166    string(2) "v2"
167    [1]=>
168    string(2) "v2"
169  }
170  [2]=>
171  array(2) {
172    [0]=>
173    &string(2) "v1"
174    [1]=>
175    &string(2) "v1"
176  }
177  [3]=>
178  array(2) {
179    [0]=>
180    &array(4) {
181      ["k1"]=>
182      &string(2) "v1"
183      ["k2"]=>
184      string(2) "v2"
185      [0]=>
186      &string(2) "v1"
187      [1]=>
188      *RECURSION*
189    }
190    [1]=>
191    &array(4) {
192      ["k1"]=>
193      &string(2) "v1"
194      ["k2"]=>
195      string(2) "v2"
196      [0]=>
197      &string(2) "v1"
198      [1]=>
199      *RECURSION*
200    }
201  }
202}
203Done
204