xref: /PHP-7.2/Zend/tests/indexing_001.phpt (revision 945a8310)
1--TEST--
2Indexing - various special cases.
3--FILE--
4<?php
5echo "*** Indexing - Testing value assignment with key ***\n";
6$array=array(1);
7$testvalues=array(null, 0, 1, true, false,'',' ',0.1,array());
8
9foreach ($testvalues as $testvalue) {
10	$testvalue['foo']=$array;
11	var_dump ($testvalue);
12}
13echo "\n*** Indexing - Testing reference assignment with key ***\n";
14
15$testvalues=array(null, 0, 1, true, false,0.1,array());
16
17foreach ($testvalues as $testvalue) {
18	$testvalue['foo']=&$array;
19	var_dump ($testvalue);
20}
21echo "*** Indexing - Testing value assignment no key ***\n";
22$array=array(1);
23$testvalues=array(null, 0, 1, true, false,0.1,array());
24
25foreach ($testvalues as $testvalue) {
26	$testvalue[]=$array;
27	var_dump ($testvalue);
28}
29echo "\n*** Indexing - Testing reference assignment no key ***\n";
30
31$testvalues=array(null, 0, 1, true, false,0.1,array());
32
33foreach ($testvalues as $testvalue) {
34	$testvalue[]=&$array;
35	var_dump ($testvalue);
36}
37
38
39echo "\nDone";
40?>
41--EXPECTF--
42*** Indexing - Testing value assignment with key ***
43array(1) {
44  ["foo"]=>
45  array(1) {
46    [0]=>
47    int(1)
48  }
49}
50
51Warning: Cannot use a scalar value as an array in %s on line %d
52int(0)
53
54Warning: Cannot use a scalar value as an array in %s on line %d
55int(1)
56
57Warning: Cannot use a scalar value as an array in %s on line %d
58bool(true)
59array(1) {
60  ["foo"]=>
61  array(1) {
62    [0]=>
63    int(1)
64  }
65}
66
67Warning: Illegal string offset 'foo' in %s on line %d
68
69Notice: Array to string conversion in %s on line %d
70string(1) "A"
71
72Warning: Illegal string offset 'foo' in %s on line %d
73
74Notice: Array to string conversion in %s on line %d
75string(1) "A"
76
77Warning: Cannot use a scalar value as an array in %s on line %d
78float(0.1)
79array(1) {
80  ["foo"]=>
81  array(1) {
82    [0]=>
83    int(1)
84  }
85}
86
87*** Indexing - Testing reference assignment with key ***
88array(1) {
89  ["foo"]=>
90  &array(1) {
91    [0]=>
92    int(1)
93  }
94}
95
96Warning: Cannot use a scalar value as an array in %s on line %d
97int(0)
98
99Warning: Cannot use a scalar value as an array in %s on line %d
100int(1)
101
102Warning: Cannot use a scalar value as an array in %s on line %d
103bool(true)
104array(1) {
105  ["foo"]=>
106  &array(1) {
107    [0]=>
108    int(1)
109  }
110}
111
112Warning: Cannot use a scalar value as an array in %s on line %d
113float(0.1)
114array(1) {
115  ["foo"]=>
116  &array(1) {
117    [0]=>
118    int(1)
119  }
120}
121*** Indexing - Testing value assignment no key ***
122array(1) {
123  [0]=>
124  array(1) {
125    [0]=>
126    int(1)
127  }
128}
129
130Warning: Cannot use a scalar value as an array in %s on line %d
131int(0)
132
133Warning: Cannot use a scalar value as an array in %s on line %d
134int(1)
135
136Warning: Cannot use a scalar value as an array in %s on line %d
137bool(true)
138array(1) {
139  [0]=>
140  array(1) {
141    [0]=>
142    int(1)
143  }
144}
145
146Warning: Cannot use a scalar value as an array in %s on line %d
147float(0.1)
148array(1) {
149  [0]=>
150  array(1) {
151    [0]=>
152    int(1)
153  }
154}
155
156*** Indexing - Testing reference assignment no key ***
157array(1) {
158  [0]=>
159  &array(1) {
160    [0]=>
161    int(1)
162  }
163}
164
165Warning: Cannot use a scalar value as an array in %s on line %d
166int(0)
167
168Warning: Cannot use a scalar value as an array in %s on line %d
169int(1)
170
171Warning: Cannot use a scalar value as an array in %s on line %d
172bool(true)
173array(1) {
174  [0]=>
175  &array(1) {
176    [0]=>
177    int(1)
178  }
179}
180
181Warning: Cannot use a scalar value as an array in %s on line %d
182float(0.1)
183array(1) {
184  [0]=>
185  &array(1) {
186    [0]=>
187    int(1)
188  }
189}
190
191Done
192