Skip to content

Commit 7a55116

Browse files
committed
Fix property hook backing value access in multi-level inheritance
Discovered by Niels when testing phpGH-17376.
1 parent c8bead8 commit 7a55116

File tree

3 files changed

+74
-1
lines changed

3 files changed

+74
-1
lines changed

NEWS

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ PHP NEWS
22
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
33
?? ??? ????, PHP 8.4.6
44

5+
- Core:
6+
. Fixed property hook backing value access in multi-level inheritance.
7+
(ilutov)
58

69
27 Feb 2025, PHP 8.4.5
710

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
--TEST--
2+
Property hooks with multi level inheritance
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
public $prop = 1;
8+
}
9+
10+
class B extends A {
11+
public $prop = 2 { get => parent::$prop::get() * 2; }
12+
}
13+
14+
class C extends B {
15+
public $prop = 3;
16+
}
17+
18+
function test(A $a) {
19+
var_dump($a);
20+
var_dump((array)$a);
21+
var_dump(unserialize(serialize($a)));
22+
var_dump(get_object_vars($a));
23+
var_dump(json_decode(json_encode($a)));
24+
}
25+
26+
test(new B);
27+
test(new C);
28+
29+
?>
30+
--EXPECTF--
31+
object(B)#%d (1) {
32+
["prop"]=>
33+
int(2)
34+
}
35+
array(1) {
36+
["prop"]=>
37+
int(2)
38+
}
39+
object(B)#%d (1) {
40+
["prop"]=>
41+
int(2)
42+
}
43+
array(1) {
44+
["prop"]=>
45+
int(4)
46+
}
47+
object(stdClass)#%d (1) {
48+
["prop"]=>
49+
int(4)
50+
}
51+
object(C)#%d (1) {
52+
["prop"]=>
53+
int(3)
54+
}
55+
array(1) {
56+
["prop"]=>
57+
int(3)
58+
}
59+
object(C)#%d (1) {
60+
["prop"]=>
61+
int(3)
62+
}
63+
array(1) {
64+
["prop"]=>
65+
int(6)
66+
}
67+
object(stdClass)#%d (1) {
68+
["prop"]=>
69+
int(6)
70+
}

Zend/zend_inheritance.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1436,7 +1436,7 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
14361436
}
14371437
if (!(parent_info->flags & ZEND_ACC_PRIVATE)) {
14381438
if (!(parent_info->ce->ce_flags & ZEND_ACC_INTERFACE)) {
1439-
child_info->prototype = parent_info;
1439+
child_info->prototype = parent_info->prototype;
14401440
}
14411441

14421442
if (UNEXPECTED((parent_info->flags & ZEND_ACC_STATIC) != (child_info->flags & ZEND_ACC_STATIC))) {

0 commit comments

Comments
 (0)