Skip to content

Commit 9c23a50

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79155
2 parents a93ce58 + 2eb3381 commit 9c23a50

File tree

2 files changed

+41
-3
lines changed

2 files changed

+41
-3
lines changed

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: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5478,15 +5478,15 @@ static zend_type zend_compile_single_typename(zend_ast *ast)
54785478
return (zend_type) ZEND_TYPE_INIT_CODE(ast->attr, 0, 0);
54795479
} else {
54805480
zend_string *class_name = zend_ast_get_str(ast);
5481-
zend_uchar type = zend_lookup_builtin_type_by_name(class_name);
5481+
zend_uchar type_code = zend_lookup_builtin_type_by_name(class_name);
54825482

5483-
if (type != 0) {
5483+
if (type_code != 0) {
54845484
if ((ast->attr & ZEND_NAME_NOT_FQ) != ZEND_NAME_NOT_FQ) {
54855485
zend_error_noreturn(E_COMPILE_ERROR,
54865486
"Type declaration '%s' must be unqualified",
54875487
ZSTR_VAL(zend_string_tolower(class_name)));
54885488
}
5489-
return (zend_type) ZEND_TYPE_INIT_CODE(type, 0, 0);
5489+
return (zend_type) ZEND_TYPE_INIT_CODE(type_code, 0, 0);
54905490
} else {
54915491
const char *correct_name;
54925492
zend_string *orig_name = zend_ast_get_str(ast);
@@ -5540,6 +5540,7 @@ static zend_type zend_compile_typename(
55405540
zend_ast *ast, zend_bool force_allow_null, zend_bool use_arena) /* {{{ */
55415541
{
55425542
zend_bool allow_null = force_allow_null;
5543+
zend_ast_attr orig_ast_attr = ast->attr;
55435544
zend_type type = ZEND_TYPE_INIT_NONE(0);
55445545
if (ast->attr & ZEND_TYPE_NULLABLE) {
55455546
allow_null = 1;
@@ -5649,6 +5650,7 @@ static zend_type zend_compile_typename(
56495650
}
56505651
}
56515652

5653+
ast->attr = orig_ast_attr;
56525654
return type;
56535655
}
56545656
/* }}} */

0 commit comments

Comments
 (0)