xref: /PHP-8.2/Zend/tests/falsetoarray.phpt (revision 052af90b)
1--TEST--
2Autovivification of false to array
3--FILE--
4<?php
5
6// control
7$undef[] = 42;
8
9// control
10$null = null;
11$null[] = 42;
12
13// control
14$false = false;
15$false = [42];
16
17print "[001]\n";
18$false = false;
19$false[] = 42;
20
21print "[002]\n";
22$ref = false;
23$ref2 = &$ref;
24$ref2[] = 42;
25
26echo "\nFunction\n";
27function ffalse(bool $a, ?bool $b, &$c, ...$d) {
28    print "[003]\n";
29    $a[] = 42;
30    print "[004]\n";
31    $b[] = 42;
32    print "[005]\n";
33    $c[] = 42;
34    print "[006]\n";
35    $d[0][] = 42;
36}
37$ref = false;
38ffalse(false, false, $ref, false);
39
40echo "\nProperties\n";
41class Cfalse {
42    public $def;
43    private $untyped = false;
44    static private $st = false;
45    static private $st2 = false;
46    static private $st3 = false;
47    public function __construct(public $pu, private $pr = false) {
48        print "[007]\n";
49        $this->def = false;
50        $this->def[] = 42;
51        print "[008]\n";
52        $this->untyped[] = 42;
53        print "[009]\n";
54        self::$st[] = 42;
55        print "[010]\n";
56        static::$st2[] = 42;
57        print "[011]\n";
58        $this::$st3[] = 42;
59        print "[012]\n";
60        $this->pu[] = 42;
61        print "[013]\n";
62        $this->pr[] = 42;
63    }
64}
65new Cfalse(false, false);
66
67echo "\nDestructuring\n";
68
69print "[014]\n";
70$add = false;
71foreach ([42] as $add[]);
72
73print "[015]\n";
74$arr = false;
75[$arr[]] = [42];
76
77print "[016]\n";
78$arr = [ 0 => [ 0 => false ] ];
79$arr[0][0][0][] = 42;
80
81print "[017]\n";
82$false = false;
83$r42 = 42;
84$false[] &= $r42;
85
86$false = false;
87$false2 = false;
88$false3 = false;
89function &g(){
90    print "[018]\n";
91    global $false;
92    $false[] = 42;
93
94    $var1 = false;
95    $GLOBALS["false2"] =& $var1;
96
97    print "[019]\n";
98    $GLOBALS["false3"][] = 42;
99
100    print "[020]\n";
101    static $f2 = false;
102    return $f2;
103}
104
105$false = &g();
106$false[] = 42;
107print "[021]\n";
108$false2[] = 42;
109
110print "[022]\n";
111$a = false;
112unset($a[0][0]);
113
114print "[023]\n";
115$a = false;
116unset($a[0]);
117
118?>
119--EXPECTF--
120[001]
121
122Deprecated: Automatic conversion of false to array is deprecated in %s
123[002]
124
125Deprecated: Automatic conversion of false to array is deprecated in %s
126
127Function
128[003]
129
130Deprecated: Automatic conversion of false to array is deprecated in %s
131[004]
132
133Deprecated: Automatic conversion of false to array is deprecated in %s
134[005]
135
136Deprecated: Automatic conversion of false to array is deprecated in %s
137[006]
138
139Deprecated: Automatic conversion of false to array is deprecated in %s
140
141Properties
142[007]
143
144Deprecated: Automatic conversion of false to array is deprecated in %s
145[008]
146
147Deprecated: Automatic conversion of false to array is deprecated in %s
148[009]
149
150Deprecated: Automatic conversion of false to array is deprecated in %s
151[010]
152
153Deprecated: Automatic conversion of false to array is deprecated in %s
154[011]
155
156Deprecated: Automatic conversion of false to array is deprecated in %s
157[012]
158
159Deprecated: Automatic conversion of false to array is deprecated in %s
160[013]
161
162Deprecated: Automatic conversion of false to array is deprecated in %s
163
164Destructuring
165[014]
166
167Deprecated: Automatic conversion of false to array is deprecated in %s
168[015]
169
170Deprecated: Automatic conversion of false to array is deprecated in %s
171[016]
172
173Deprecated: Automatic conversion of false to array is deprecated in %s
174[017]
175
176Deprecated: Automatic conversion of false to array is deprecated in %s
177[018]
178
179Deprecated: Automatic conversion of false to array is deprecated in %s
180[019]
181
182Deprecated: Automatic conversion of false to array is deprecated in %s
183[020]
184
185Deprecated: Automatic conversion of false to array is deprecated in %s
186[021]
187
188Deprecated: Automatic conversion of false to array is deprecated in %s
189[022]
190
191Deprecated: Automatic conversion of false to array is deprecated in %s
192[023]
193
194Deprecated: Automatic conversion of false to array is deprecated in %s
195