Skip to content

Commit

Permalink
Fix property hook backing value access in multi-level inheritance
Browse files Browse the repository at this point in the history
Discovered by Niels when testing GH-17376.
  • Loading branch information
iluuu1994 committed Feb 26, 2025
1 parent c8bead8 commit 7a55116
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ PHP NEWS
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.4.6

- Core:
. Fixed property hook backing value access in multi-level inheritance.
(ilutov)

27 Feb 2025, PHP 8.4.5

Expand Down
70 changes: 70 additions & 0 deletions Zend/tests/property_hooks/multi_level_inheritance.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
--TEST--
Property hooks with multi level inheritance
--FILE--
<?php

class A {
public $prop = 1;
}

class B extends A {
public $prop = 2 { get => parent::$prop::get() * 2; }
}

class C extends B {
public $prop = 3;
}

function test(A $a) {
var_dump($a);
var_dump((array)$a);
var_dump(unserialize(serialize($a)));
var_dump(get_object_vars($a));
var_dump(json_decode(json_encode($a)));
}

test(new B);
test(new C);

?>
--EXPECTF--
object(B)#%d (1) {
["prop"]=>
int(2)
}
array(1) {
["prop"]=>
int(2)
}
object(B)#%d (1) {
["prop"]=>
int(2)
}
array(1) {
["prop"]=>
int(4)
}
object(stdClass)#%d (1) {
["prop"]=>
int(4)
}
object(C)#%d (1) {
["prop"]=>
int(3)
}
array(1) {
["prop"]=>
int(3)
}
object(C)#%d (1) {
["prop"]=>
int(3)
}
array(1) {
["prop"]=>
int(6)
}
object(stdClass)#%d (1) {
["prop"]=>
int(6)
}
2 changes: 1 addition & 1 deletion Zend/zend_inheritance.c
Original file line number Diff line number Diff line change
Expand Up @@ -1436,7 +1436,7 @@ static void do_inherit_property(zend_property_info *parent_info, zend_string *ke
}
if (!(parent_info->flags & ZEND_ACC_PRIVATE)) {
if (!(parent_info->ce->ce_flags & ZEND_ACC_INTERFACE)) {
child_info->prototype = parent_info;
child_info->prototype = parent_info->prototype;
}

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

0 comments on commit 7a55116

Please sign in to comment.