com php-src: Fixed bug #78810: NEWS Zend/tests/bug78810.phpt Zend/zend_object_handlers.c

From: Date: Fri, 15 Nov 2019 11:06:17 +0000
Subject: com php-src: Fixed bug #78810: NEWS Zend/tests/bug78810.phpt Zend/zend_object_handlers.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-109259@lists.php.net to get a copy of this message
Commit: 266f3a02bce4e4c68f93744540c9bfd32516c868 Author: Nikita Popov <nikita.ppv@gmail.com> Fri, 15 Nov 2019 12:06:17 +0100 Parents: a5683e65da2927613c5819747aee41ece9068705 Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=266f3a02bce4e4c68f93744540c9bfd32516c868 Log: Fixed bug #78810 Bugs: https://bugs.php.net/78810 Changed paths: M NEWS A Zend/tests/bug78810.phpt M Zend/zend_object_handlers.c Diff: diff --git a/NEWS b/NEWS index 740abaa4214..a767481238e 100644 --- a/NEWS +++ b/NEWS @@ -1,5 +1,12 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| + +?? ??? ????, PHP 7.4.1 + +- Core: + . Fixed bug #78810 (RW fetches do not throw "uninitialized property" + exception). (Nikita) + ?? ??? ????, PHP 7.4.0RC6 - Core: diff --git a/Zend/tests/bug78810.phpt b/Zend/tests/bug78810.phpt new file mode 100644 index 00000000000..0fd56f0ceda --- /dev/null +++ b/Zend/tests/bug78810.phpt @@ -0,0 +1,25 @@ +--TEST-- +Bug #78810: RW fetches do not throw "uninitialized property" exception +--FILE-- +<?php + +class Test { + public int $i; +} + +$test = new Test; +try { + $test->i++; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} +try { + $test->i += 1; +} catch (Error $e) { + echo $e->getMessage(), "\n"; +} + +?> +--EXPECT-- +Typed property Test::$i must not be accessed before initialization +Typed property Test::$i must not be accessed before initialization diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 5ac64fffb19..3a7b83ed63f 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -1044,8 +1044,16 @@ ZEND_API zval *zend_std_get_property_ptr_ptr(zval *object, zval *member, int typ if (EXPECTED(!zobj->ce->__get) || UNEXPECTED((*zend_get_property_guard(zobj, name)) & IN_GET)) { if (UNEXPECTED(type == BP_VAR_RW || type == BP_VAR_R)) { - ZVAL_NULL(retval); - zend_error(E_NOTICE, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); + if (UNEXPECTED(prop_info)) { + zend_throw_error(NULL, + "Typed property %s::$%s must not be accessed before initialization", + ZSTR_VAL(prop_info->ce->name), + ZSTR_VAL(name)); + retval = &EG(error_zval); + } else { + ZVAL_NULL(retval); + zend_error(E_NOTICE, "Undefined property: %s::$%s", ZSTR_VAL(zobj->ce->name), ZSTR_VAL(name)); + } } } else { /* we do have getter - fail and let it try again with usual get/set */

« previous php.cvs (#109259) next »