1--TEST--
2Evaluation order during assignments.
3--FILE--
4<?php
5
6// simple case with missing element
7$f = array("hello","item2","bye");
8list($a,,$b) = $f;
9echo "A=$a B=$b\n";
10
11
12// Warning: Cannot use a scalar value as an array in %s on line %d
13try {
14    $c[$c=1] = 1;
15} catch (Error $e) {
16    echo $e->getMessage(), "\n";
17}
18
19// i++ evaluated first, so $d[0] is 10
20$d = array(0,10);
21$i = 0;
22$d[$i++] = $i*10;
23// expected array is 10,10
24var_dump($d);
25
26// the f++++ makes f into 2, so $e 0 and 1 should both be 30
27$e = array(0,0);
28$f = 0;
29$g1 = array(10,10);
30$g2 = array(20,20);
31$g3 = array(30,30);
32$g = array($g1,$g2,$g3);
33list($e[$f++],$e[$f++]) = $g[2];
34// expect 30,30
35var_dump($e);
36
37
38$i1 = array(1,2);
39$i2 = array(10,20);
40$i3 = array(100,200);
41$i4 = array(array(1000,2000),3000);
42$i = array($i1,$i2,$i3,$i4);
43$j = array(0,0,0);
44$h = 0;
45// a list of lists
46list(list($j[$h++],$j[$h++]),$j[$h++]) = $i[3];
47var_dump($j);
48
49
50// list of lists with just variable assignments - expect 100,200,300
51$k3 = array(100,200);
52$k = array($k3,300);
53list(list($l,$m),$n) = $k;
54echo "L=$l M=$m N=$n\n";
55
56
57// expect $x and $y to be null - this fails on php.net 5.2.1 (invalid opcode) - fixed in 5.2.3
58list($o,$p) = 20;
59echo "O=$o and P=$p\n";
60
61
62// list of lists with blanks and nulls expect 10 20 40 50 60 70 80
63$q1 = array(10,20,30,40);
64$q2 = array(50,60);
65$q3 = array($q1,$q2,null,70);
66$q4 = array($q3,null,80);
67
68list(list(list($r,$s,,$t),list($u,$v),,$w),,$x) = $q4;
69echo "$r $s $t $u $v $w $x\n";
70
71
72// expect y and z to be undefined
73list($y,$z) = array();
74echo "Y=$y,Z=$z\n";
75
76// expect h to be defined and be 10
77list($aa,$bb) = array(10);
78echo "AA=$aa\n";
79
80// expect cc and dd to be 10 and 30
81list($cc,,$dd) = array(10,20,30,40);
82echo "CC=$cc DD=$dd\n";
83
84// expect the inner array to be defined
85$ee = array("original array");
86function f() {
87  global $ee;
88  $ee = array("array created in f()");
89  return 1;
90}
91$ee["array entry created after f()"][f()] = "hello";
92print_r($ee);
93
94?>
95--EXPECTF--
96A=hello B=bye
97Cannot use a scalar value as an array
98array(2) {
99  [0]=>
100  int(10)
101  [1]=>
102  int(10)
103}
104array(2) {
105  [0]=>
106  int(30)
107  [1]=>
108  int(30)
109}
110array(3) {
111  [0]=>
112  int(1000)
113  [1]=>
114  int(2000)
115  [2]=>
116  int(3000)
117}
118L=100 M=200 N=300
119O= and P=
12010 20 40 50 60 70 80
121
122Warning: Undefined array key 0 in %s on line %d
123
124Warning: Undefined array key 1 in %s on line %d
125Y=,Z=
126
127Warning: Undefined array key 1 in %s on line %d
128AA=10
129CC=10 DD=30
130Array
131(
132    [0] => array created in f()
133    [array entry created after f()] => Array
134        (
135            [1] => hello
136        )
137
138)
139