Skip to content

Commit 266f3a0

Browse files
committed
Fixed bug #78810
1 parent a5683e6 commit 266f3a0

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

NEWS

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
3+
4+
?? ??? ????, PHP 7.4.1
5+
6+
- Core:
7+
. Fixed bug #78810 (RW fetches do not throw "uninitialized property"
8+
exception). (Nikita)
9+
310
?? ??? ????, PHP 7.4.0RC6
411

512
- Core:

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
@@ -1044,8 +1044,16 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int typ
10441044
if (EXPECTED(!zobj->ce->__get) ||
10451045
UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET)) {
10461046
if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) {
1047-
ZVAL_NULL(retval);
1048-
zend_error(E_NOTICE, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1047+
if (UNEXPECTED(prop_info)) {
1048+
zend_throw_error(NULL,
1049+
"Typed property %s::$%s must not be accessed before initialization",
1050+
ZSTR_VAL(prop_info->ce->name),
1051+
ZSTR_VAL(name));
1052+
retval = &EG(error_zval);
1053+
} else {
1054+
ZVAL_NULL(retval);
1055+
zend_error(E_NOTICE, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name));
1056+
}
10491057
}
10501058
} else {
10511059
/* we do have getter - fail and let it try again with usual get/set */

0 commit comments

Comments
 (0)