com php-src: Fixed bug #79862: NEWS Zend/tests/bug79862.phpt Zend/zend_object_handlers.c
| From: | Nikita Popov | Date: | Wed, 15 Jul 2020 12:59:55 +0000 |
| Subject: | com php-src: Fixed bug #79862: NEWS Zend/tests/bug79862.phpt Zend/zend_object_handlers.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-112175@lists.php.net to get a copy of this message | ||
Commit: e8430b592f977a8aaccf13f3213ff0d987388d13
Author: Nikita Popov <nikita.ppv@gmail.com> Wed, 15 Jul 2020 14:59:55 +0200
Parents: ee7c7a8e26b99e3b25a7d41abfe1a2c37b3f6968
Branches: PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=e8430b592f977a8aaccf13f3213ff0d987388d13
Log:
Fixed bug #79862
While normally a private property in the active scope would take
priority, we should not use this if it has the wrong "staticness".
Bugs:
https://bugs.php.net/79862
Changed paths:
M NEWS
A Zend/tests/bug79862.phpt
M Zend/zend_object_handlers.c
Diff:
diff --git a/NEWS b/NEWS
index 09f59a02eb..3c688cbaa3 100644
--- a/NEWS
+++ b/NEWS
@@ -25,6 +25,8 @@ PHP NEWS
array write fetch). (Nikita)
. Fixed bug #79793 (Use after free if string used in undefined index warning
is changed). (Nikita)
+ . Fixed bug #79862 (Public non-static property in child should take priority
+ over private static). (Nikita)
- Fileinfo:
. Fixed bug #79756 (finfo_file crash (FILEINFO_MIME)). (cmb)
diff --git a/Zend/tests/bug79862.phpt b/Zend/tests/bug79862.phpt
new file mode 100644
index 0000000000..b923da78b4
--- /dev/null
+++ b/Zend/tests/bug79862.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Bug #79862: Public non-static property in child should take priority over private static
+--FILE--
+<?php
+
+class a {
+ private static $prop1;
+ private static $prop2;
+ private $prop3;
+ private $prop4;
+ private static $prop5;
+ private static $prop6;
+ public function __construct() {
+ $this->prop1 = 1;
+ $this->prop2 = 2;
+ $this->prop3 = 3;
+ $this->prop4 = 4;
+ $this->prop5 = 5;
+ $this->prop6 = 6;
+ var_dump(self::$prop1);
+ var_dump(self::$prop2);
+ var_dump(self::$prop5);
+ var_dump(self::$prop6);
+ var_dump($this);
+ }
+}
+class c extends a {
+ public $prop1;
+ protected $prop2;
+ public static $prop3;
+ protected static $prop4;
+ public static $prop5;
+ protected static $prop6;
+}
+
+$c = new c;
+
+?>
+--EXPECTF--
+Notice: Accessing static property c::$prop5 as non static in %s on line %d
+
+Notice: Accessing static property c::$prop6 as non static in %s on line %d
+NULL
+NULL
+NULL
+NULL
+object(c)#1 (6) {
+ ["prop1"]=>
+ int(1)
+ ["prop2":protected]=>
+ int(2)
+ ["prop3":"a":private]=>
+ int(3)
+ ["prop4":"a":private]=>
+ int(4)
+ ["prop5"]=>
+ int(5)
+ ["prop6"]=>
+ int(6)
+}
diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c
index 5be63b4cd7..c058c1cf49 100644
--- a/Zend/zend_object_handlers.c
+++ b/Zend/zend_object_handlers.c
@@ -421,7 +421,11 @@ dynamic:
if (flags & ZEND_ACC_CHANGED) {
zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
- if (p) {
+ /* If there is a public/protected instance property on ce, don't try to use a
+ * private static property on scope. If both are static, prefer the static
+ * property on scope. This will throw a static property notice, rather than
+ * a visibility error. */
+ if (p && (!(p->flags & ZEND_ACC_STATIC) || (flags & ZEND_ACC_STATIC))) {
property_info = p;
flags = property_info->flags;
goto found;