1--TEST--
2Test array_push() function : usage variations - referenced variables
3--INI--
4allow_call_time_pass_reference=on
5--FILE--
6<?php
7/* Prototype  : int array_push(array $stack, mixed $var [, mixed $...])
8 * Description: Pushes elements onto the end of the array
9 * Source code: ext/standard/array.c
10 */
11
12/*
13 * Test array_push when:
14 * 1. passed referenced variables as $var arguments
15 * 2. $var argument is a reference to $stack argument
16 */
17
18echo "*** Testing array_push() : usage variations ***\n";
19
20$var1 = 'a';
21$var2 = 'b';
22$var3 = 'c';
23$var4 = 'x';
24$var5 = 'y';
25$var6 = 'z';
26
27$array = array(1, 2, 3);
28
29echo "\n-- Pass array_push referenced varialbes as \$var arguments --\n";
30var_dump(array_push($array, &$var1, &$var2, &$var3, &$var4, &$var5, &$var6));
31var_dump($array);
32
33echo "\n-- Pass \$var argument which is a reference to \$stack argument --\n";
34var_dump(array_push($array, &$array));
35var_dump($array);
36
37echo "Done";
38?>
39--EXPECTF--
40*** Testing array_push() : usage variations ***
41
42-- Pass array_push referenced varialbes as $var arguments --
43int(9)
44array(9) {
45  [0]=>
46  int(1)
47  [1]=>
48  int(2)
49  [2]=>
50  int(3)
51  [3]=>
52  &string(1) "a"
53  [4]=>
54  &string(1) "b"
55  [5]=>
56  &string(1) "c"
57  [6]=>
58  &string(1) "x"
59  [7]=>
60  &string(1) "y"
61  [8]=>
62  &string(1) "z"
63}
64
65-- Pass $var argument which is a reference to $stack argument --
66int(10)
67array(10) {
68  [0]=>
69  int(1)
70  [1]=>
71  int(2)
72  [2]=>
73  int(3)
74  [3]=>
75  &string(1) "a"
76  [4]=>
77  &string(1) "b"
78  [5]=>
79  &string(1) "c"
80  [6]=>
81  &string(1) "x"
82  [7]=>
83  &string(1) "y"
84  [8]=>
85  &string(1) "z"
86  [9]=>
87  &array(10) {
88    [0]=>
89    int(1)
90    [1]=>
91    int(2)
92    [2]=>
93    int(3)
94    [3]=>
95    &string(1) "a"
96    [4]=>
97    &string(1) "b"
98    [5]=>
99    &string(1) "c"
100    [6]=>
101    &string(1) "x"
102    [7]=>
103    &string(1) "y"
104    [8]=>
105    &string(1) "z"
106    [9]=>
107    *RECURSION*
108  }
109}
110Done
111