File: falsetoarray.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (194 lines) | stat: -rw-r--r-- 3,795 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
--TEST--
Autovivification of false to array
--FILE--
<?php

// control
$undef[] = 42;

// control
$null = null;
$null[] = 42;

// control
$false = false;
$false = [42];

print "[001]\n";
$false = false;
$false[] = 42;

print "[002]\n";
$ref = false;
$ref2 = &$ref;
$ref2[] = 42;

echo "\nFunction\n";
function ffalse(bool $a, ?bool $b, &$c, ...$d) {
    print "[003]\n";
    $a[] = 42;
    print "[004]\n";
    $b[] = 42;
    print "[005]\n";
    $c[] = 42;
    print "[006]\n";
    $d[0][] = 42;
}
$ref = false;
ffalse(false, false, $ref, false);

echo "\nProperties\n";
class Cfalse {
    public $def;
    private $untyped = false;
    static private $st = false;
    static private $st2 = false;
    static private $st3 = false;
    public function __construct(public $pu, private $pr = false) {
        print "[007]\n";
        $this->def = false;
        $this->def[] = 42;
        print "[008]\n";
        $this->untyped[] = 42;
        print "[009]\n";
        self::$st[] = 42;
        print "[010]\n";
        static::$st2[] = 42;
        print "[011]\n";
        $this::$st3[] = 42;
        print "[012]\n";
        $this->pu[] = 42;
        print "[013]\n";
        $this->pr[] = 42;
    }
}
new Cfalse(false, false);

echo "\nDestructuring\n";

print "[014]\n";
$add = false;
foreach ([42] as $add[]);

print "[015]\n";
$arr = false;
[$arr[]] = [42];

print "[016]\n";
$arr = [ 0 => [ 0 => false ] ];
$arr[0][0][0][] = 42;

print "[017]\n";
$false = false;
$r42 = 42;
$false[] &= $r42;

$false = false;
$false2 = false;
$false3 = false;
function &g(){
    print "[018]\n";
    global $false;
    $false[] = 42;

    $var1 = false;
    $GLOBALS["false2"] =& $var1;

    print "[019]\n";
    $GLOBALS["false3"][] = 42;

    print "[020]\n";
    static $f2 = false;
    return $f2;
}

$false = &g();
$false[] = 42;
print "[021]\n";
$false2[] = 42;

print "[022]\n";
$a = false;
unset($a[0][0]);

print "[023]\n";
$a = false;
unset($a[0]);

?>
--EXPECTF--
[001]

Deprecated: Automatic conversion of false to array is deprecated in %s
[002]

Deprecated: Automatic conversion of false to array is deprecated in %s

Function
[003]

Deprecated: Automatic conversion of false to array is deprecated in %s
[004]

Deprecated: Automatic conversion of false to array is deprecated in %s
[005]

Deprecated: Automatic conversion of false to array is deprecated in %s
[006]

Deprecated: Automatic conversion of false to array is deprecated in %s

Properties
[007]

Deprecated: Automatic conversion of false to array is deprecated in %s
[008]

Deprecated: Automatic conversion of false to array is deprecated in %s
[009]

Deprecated: Automatic conversion of false to array is deprecated in %s
[010]

Deprecated: Automatic conversion of false to array is deprecated in %s
[011]

Deprecated: Automatic conversion of false to array is deprecated in %s
[012]

Deprecated: Automatic conversion of false to array is deprecated in %s
[013]

Deprecated: Automatic conversion of false to array is deprecated in %s

Destructuring
[014]

Deprecated: Automatic conversion of false to array is deprecated in %s
[015]

Deprecated: Automatic conversion of false to array is deprecated in %s
[016]

Deprecated: Automatic conversion of false to array is deprecated in %s
[017]

Deprecated: Automatic conversion of false to array is deprecated in %s
[018]

Deprecated: Automatic conversion of false to array is deprecated in %s
[019]

Deprecated: Automatic conversion of false to array is deprecated in %s
[020]

Deprecated: Automatic conversion of false to array is deprecated in %s
[021]

Deprecated: Automatic conversion of false to array is deprecated in %s
[022]

Deprecated: Automatic conversion of false to array is deprecated in %s
[023]

Deprecated: Automatic conversion of false to array is deprecated in %s