Skip to content

Commit dabc7c5

Browse files
Tyson's prototype
Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
1 parent b642138 commit dabc7c5

File tree

4 files changed

+313
-0
lines changed

4 files changed

+313
-0
lines changed

Zend/tests/falsetoarray.phpt

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
--TEST--
2+
Autovivification of false to array
3+
--FILE--
4+
<?php
5+
6+
// no
7+
$undef[] = 42;
8+
9+
// no
10+
$null = null;
11+
$null[] = 42;
12+
13+
// yes
14+
$false = false;
15+
$false[] = 42;
16+
17+
// yes
18+
$ref = false;
19+
$ref2 = &$ref;
20+
$ref2[] = 42;
21+
22+
echo "now function\n";
23+
function ffalse(bool $a, ?bool $b, &$c, ...$d) {
24+
// yes
25+
$a[] = 42;
26+
// yes
27+
$b[] = 42;
28+
// yes
29+
$c[] = 42;
30+
// yes
31+
$d[0][] = 42;
32+
}
33+
$ref = false;
34+
ffalse(false, false, $ref, false);
35+
36+
echo "now class\n";
37+
class Cfalse {
38+
public $def;
39+
private $untyped = false;
40+
static private $st = false;
41+
static private $st2 = false;
42+
static private $st3 = false;
43+
public function __construct(public $pu, private $pr = false) {
44+
// yes
45+
$this->def = false;
46+
$this->def[] = 42;
47+
// yes
48+
$this->untyped[] = 42;
49+
// yes
50+
self::$st[] = 42;
51+
// yes
52+
static::$st2[] = 42;
53+
// yes
54+
$this::$st3[] = 42;
55+
// yes
56+
$this->pu[] = 42;
57+
// yes
58+
$this->pr[] = 42;
59+
}
60+
}
61+
new Cfalse(false, false);
62+
63+
?>
64+
--EXPECTF--
65+
Deprecated: Automatic conversion of false to array is deprecated in %s
66+
67+
Deprecated: Automatic conversion of false to array is deprecated in %s
68+
now function
69+
70+
Deprecated: Automatic conversion of false to array is deprecated in %s
71+
72+
Deprecated: Automatic conversion of false to array is deprecated in %s
73+
74+
Deprecated: Automatic conversion of false to array is deprecated in %s
75+
76+
Deprecated: Automatic conversion of false to array is deprecated in %s
77+
now class
78+
79+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 43
80+
81+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 45
82+
83+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 47
84+
85+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 49
86+
87+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 51
88+
89+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 53
90+
91+
Deprecated: Automatic conversion of false to array is deprecated in %s on line 55

Zend/zend_execute.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,9 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
22902290
return;
22912291
}
22922292
}
2293+
if (Z_TYPE_P(container) == IS_FALSE) {
2294+
zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
2295+
}
22932296
array_init(container);
22942297
goto fetch_from_array;
22952298
} else {
@@ -2345,6 +2348,9 @@ static zend_always_inline void zend_fetch_dimension_address(zval *result, zval *
23452348
ZVAL_UNDEFINED_OP1();
23462349
}
23472350
if (type != BP_VAR_UNSET) {
2351+
if (Z_TYPE_P(container) == IS_FALSE) {
2352+
zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
2353+
}
23482354
array_init(container);
23492355
goto fetch_from_array;
23502356
} else {
@@ -2873,6 +2879,12 @@ static zend_always_inline void zend_fetch_property_address(zval *result, zval *c
28732879

28742880
ZVAL_INDIRECT(result, ptr);
28752881
if (flags) {
2882+
if (flags == ZEND_FETCH_DIM_WRITE) {
2883+
if (Z_TYPE_P(ptr) == IS_FALSE) {
2884+
zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
2885+
}
2886+
}
2887+
28762888
zend_property_info *prop_info;
28772889

28782890
if (prop_op_type == IS_CONST) {

Zend/zend_vm_def.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,11 @@ ZEND_VM_C_LABEL(assign_dim_op_new_array):
12101210
if (OP1_TYPE == IS_CV && UNEXPECTED(Z_TYPE_INFO_P(container) == IS_UNDEF)) {
12111211
ZVAL_UNDEFINED_OP1();
12121212
}
1213+
1214+
if (Z_TYPE_P(container) == IS_FALSE) {
1215+
zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
1216+
}
1217+
12131218
ZVAL_ARR(container, zend_new_array(8));
12141219
ZEND_VM_C_GOTO(assign_dim_op_new_array);
12151220
} else {
@@ -2601,6 +2606,11 @@ ZEND_VM_C_LABEL(try_assign_dim_array):
26012606
FREE_OP_DATA();
26022607
}
26032608
} else if (EXPECTED(Z_TYPE_P(object_ptr) <= IS_FALSE)) {
2609+
2610+
if (Z_TYPE_P(object_ptr) == IS_FALSE) {
2611+
zend_error(E_DEPRECATED, "Automatic conversion of false to array is deprecated");
2612+
}
2613+
26042614
if (Z_ISREF_P(orig_object_ptr)
26052615
&& ZEND_REF_HAS_TYPE_SOURCES(Z_REF_P(orig_object_ptr))
26062616
&& !zend_verify_ref_array_assignable(Z_REF_P(orig_object_ptr))) {

0 commit comments

Comments
 (0)