Skip to content

Commit 5785a15

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fixed bug #79862
2 parents 9a1a94e + e8430b5 commit 5785a15

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

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
@@ -310,7 +310,11 @@ static zend_always_inline uintptr_t zend_get_property_offset(zend_class_entry *c
310310
if (flags & ZEND_ACC_CHANGED) {
311311
zend_property_info *p = zend_get_parent_private_property(scope, ce, member);
312312

313-
if (p) {
313+
/* If there is a public/protected instance property on ce, don't try to use a
314+
* private static property on scope. If both are static, prefer the static
315+
* property on scope. This will throw a static property notice, rather than
316+
* a visibility error. */
317+
if (p && (!(p->flags & ZEND_ACC_STATIC) || (flags & ZEND_ACC_STATIC))) {
314318
property_info = p;
315319
flags = property_info->flags;
316320
goto found;

0 commit comments

Comments
 (0)