Skip to content

Commit 716fdac

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #78810
2 parents 03b7833 + 266f3a0 commit 716fdac

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

Zend/tests/bug78810.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
Bug #78810: RW fetches do not throw "uninitialized property" exception
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
public int $i;
8+
}
9+
10+
$test = new Test;
11+
try {
12+
$test->i++;
13+
} catch (Error $e) {
14+
echo $e->getMessage(), "\n";
15+
}
16+
try {
17+
$test->i += 1;
18+
} catch (Error $e) {
19+
echo $e->getMessage(), "\n";
20+
}
21+
22+
?>
23+
--EXPECT--
24+
Typed property Test::$i must not be accessed before initialization
25+
Typed property Test::$i must not be accessed before initialization

Zend/zend_object_handlers.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,8 +1013,16 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zend_object *zobj, zend_string *nam
10131013
if (EXPECTED(!zobj->ce->__get) ||
10141014
UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET)) {
10151015
if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
1016-
ZVAL_NULL(retval);
1017-
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1016+
if (UNEXPECTED(prop_info)) {
1017+
zend_throw_error(NULL,
1018+
"Typed property %s::$%s must not be accessed before initialization",
1019+
ZSTR_VAL(prop_info->ce->name),
1020+
ZSTR_VAL(name));
1021+
retval = &EG(error_zval);
1022+
} else {
1023+
ZVAL_NULL(retval);
1024+
zend_error(E_WARNING, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1025+
}
10181026
}
10191027
} else {
10201028
/* we do have getter - fail and let it try again with usual get/set */

0 commit comments

Comments
 (0)