Skip to content

Commit 2eb3381

Browse files
committed
Fixed bug #79155
Make sure we only unset the NULLABLE flag temporarily for class resolution, as the same type may be compiled multiple types.
1 parent ea3afcb commit 2eb3381

File tree

3 files changed

+48
-5
lines changed

3 files changed

+48
-5
lines changed

NEWS

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ PHP NEWS
33
?? ??? ????, PHP 7.4.3
44

55
- Core:
6-
. Fixed bug ##79146 (cscript can fail to run on some systems). (clarodeus)
6+
. Fixed bug #79146 (cscript can fail to run on some systems). (clarodeus)
7+
. Fixed bug #79155 (Property nullability lost when using multiple property
8+
definition). (Nikita)
79

810
- CURL:
911
. Fixed bug #79078 (Hypothetical use-after-free in curl_multi_add_handle()).

Zend/tests/bug79155.phpt

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Bug #79155: Property nullability lost when using multiple property definition
3+
--FILE--
4+
<?php
5+
6+
class Foo {
7+
public ?string $a, $b;
8+
public ?stdClass $c, $d;
9+
}
10+
11+
$t = new Foo;
12+
$t->a = "str";
13+
$t->b = "str";
14+
$t->c = new stdClass;
15+
$t->d = new stdClass;
16+
17+
var_dump($t->a, $t->b, $t->c, $t->d);
18+
19+
$t->a = null;
20+
$t->b = null;
21+
$t->c = null;
22+
$t->d = null;
23+
var_dump($t->a, $t->b, $t->c, $t->d);
24+
25+
?>
26+
--EXPECT--
27+
string(3) "str"
28+
string(3) "str"
29+
object(stdClass)#2 (0) {
30+
}
31+
object(stdClass)#3 (0) {
32+
}
33+
NULL
34+
NULL
35+
NULL
36+
NULL

Zend/zend_compile.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5282,6 +5282,8 @@ ZEND_API void zend_set_function_arg_flags(zend_function *func) /* {{{ */
52825282
static zend_type zend_compile_typename(zend_ast *ast, zend_bool force_allow_null) /* {{{ */
52835283
{
52845284
zend_bool allow_null = force_allow_null;
5285+
zend_ast_attr orig_ast_attr = ast->attr;
5286+
zend_type type;
52855287
if (ast->attr & ZEND_TYPE_NULLABLE) {
52865288
allow_null = 1;
52875289
ast->attr &= ~ZEND_TYPE_NULLABLE;
@@ -5291,15 +5293,15 @@ static zend_type zend_compile_typename(zend_ast *ast, zend_bool force_allow_null
52915293
return ZEND_TYPE_ENCODE(ast->attr, allow_null);
52925294
} else {
52935295
zend_string *class_name = zend_ast_get_str(ast);
5294-
zend_uchar type = zend_lookup_builtin_type_by_name(class_name);
5296+
zend_uchar type_code = zend_lookup_builtin_type_by_name(class_name);
52955297

5296-
if (type != 0) {
5298+
if (type_code != 0) {
52975299
if ((ast->attr & ZEND_NAME_NOT_FQ) != ZEND_NAME_NOT_FQ) {
52985300
zend_error_noreturn(E_COMPILE_ERROR,
52995301
"Type declaration '%s' must be unqualified",
53005302
ZSTR_VAL(zend_string_tolower(class_name)));
53015303
}
5302-
return ZEND_TYPE_ENCODE(type, allow_null);
5304+
type = ZEND_TYPE_ENCODE(type_code, allow_null);
53035305
} else {
53045306
uint32_t fetch_type = zend_get_class_fetch_type_ast(ast);
53055307
if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
@@ -5310,9 +5312,12 @@ static zend_type zend_compile_typename(zend_ast *ast, zend_bool force_allow_null
53105312
zend_string_addref(class_name);
53115313
}
53125314

5313-
return ZEND_TYPE_ENCODE_CLASS(class_name, allow_null);
5315+
type = ZEND_TYPE_ENCODE_CLASS(class_name, allow_null);
53145316
}
53155317
}
5318+
5319+
ast->attr = orig_ast_attr;
5320+
return type;
53165321
}
53175322
/* }}} */
53185323

0 commit comments

Comments
 (0)