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