Skip to content

Commit a49d53b

Browse files
committed
Don't skip uninitialized typed props in get_class_vars()
For bug #78319.
1 parent d968027 commit a49d53b

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
get_class_vars() returns uninitialized typed properties with a null value
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public static int $int1;
8+
public static int $int2 = 42;
9+
public int $int3;
10+
public int $int4 = 42;
11+
}
12+
13+
var_dump(get_class_vars(Test::class));
14+
15+
?>
16+
--EXPECT--
17+
array(4) {
18+
["int3"]=>
19+
NULL
20+
["int4"]=>
21+
int(42)
22+
["int1"]=>
23+
NULL
24+
["int2"]=>
25+
int(42)
26+
}

Zend/zend_builtin_functions.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1123,12 +1123,17 @@ static void add_class_vars(zend_class_entry *scope, zend_class_entry *ce, int st
11231123
} else if (!statics && (prop_info->flags & ZEND_ACC_STATIC) == 0) {
11241124
prop = &ce->default_properties_table[OBJ_PROP_TO_NUM(prop_info->offset)];
11251125
}
1126-
if (!prop || Z_TYPE_P(prop) == IS_UNDEF) {
1126+
if (!prop) {
11271127
continue;
11281128
}
11291129

1130-
/* copy: enforce read only access */
1131-
ZVAL_COPY_OR_DUP(&prop_copy, prop);
1130+
if (Z_ISUNDEF_P(prop)) {
1131+
/* Return uninitialized typed properties as a null value */
1132+
ZVAL_NULL(&prop_copy);
1133+
} else {
1134+
/* copy: enforce read only access */
1135+
ZVAL_COPY_OR_DUP(&prop_copy, prop);
1136+
}
11321137
prop = &prop_copy;
11331138

11341139
/* this is necessary to make it able to work with default array

0 commit comments

Comments
 (0)