Skip to content

Commit e8430b5

Browse files
committed
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".
1 parent ee7c7a8 commit e8430b5

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ PHP NEWS
2525
array write fetch). (Nikita)
2626
. Fixed bug #79793 (Use after free if string used in undefined index warning
2727
is changed). (Nikita)
28+
. Fixed bug #79862 (Public non-static property in child should take priority
29+
over private static). (Nikita)
2830

2931
- Fileinfo:
3032
. Fixed bug #79756 (finfo_file crash (FILEINFO_MIME)). (cmb)

Zend/tests/bug79862.phpt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--TEST--
2+
Bug #79862: Public non-static property in child should take priority over private static
3+
--FILE--
4+
<?php
5+
6+
class a {
7+
private static $prop1;
8+
private static $prop2;
9+
private $prop3;
10+
private $prop4;
11+
private static $prop5;
12+
private static $prop6;
13+
public function __construct() {
14+
$this->prop1 = 1;
15+
$this->prop2 = 2;
16+
$this->prop3 = 3;
17+
$this->prop4 = 4;
18+
$this->prop5 = 5;
19+
$this->prop6 = 6;
20+
var_dump(self::$prop1);
21+
var_dump(self::$prop2);
22+
var_dump(self::$prop5);
23+
var_dump(self::$prop6);
24+
var_dump($this);
25+
}
26+
}
27+
class c extends a {
28+
public $prop1;
29+
protected $prop2;
30+
public static $prop3;
31+
protected static $prop4;
32+
public static $prop5;
33+
protected static $prop6;
34+
}
35+
36+
$c = new c;
37+
38+
?>
39+
--EXPECTF--
40+
Notice: Accessing static property c::$prop5 as non static in %s on line %d
41+
42+
Notice: Accessing static property c::$prop6 as non static in %s on line %d
43+
NULL
44+
NULL
45+
NULL
46+
NULL
47+
object(c)#1 (6) {
48+
["prop1"]=>
49+
int(1)
50+
["prop2":protected]=>
51+
int(2)
52+
["prop3":"a":private]=>
53+
int(3)
54+
["prop4":"a":private]=>
55+
int(4)
56+
["prop5"]=>
57+
int(5)
58+
["prop6"]=>
59+
int(6)
60+
}

Zend/zend_object_handlers.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,11 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
421421
if (flags & ZEND_ACC_CHANGED) {
422422
zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
423423

424-
if (p) {
424+
/* If there is a public/protected instance property on ce, don't try to use a
425+
* private static property on scope. If both are static, prefer the static
426+
* property on scope. This will throw a static property notice, rather than
427+
* a visibility error. */
428+
if (p && (!(p->flags & ZEND_ACC_STATIC) || (flags & ZEND_ACC_STATIC))) {
425429
property_info = p;
426430
flags = property_info->flags;
427431
goto found;

0 commit comments

Comments
 (0)