Skip to content

Commit fbf11f9

Browse files
committed
Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4: Fix accessing of overridden private property in get_object_vars()
2 parents 28d8b8f + f5fc755 commit fbf11f9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ PHP NEWS
88
. Fixed bug GH-19844 (Don't bail when closing resources on shutdown). (ilutov)
99
. Fixed deprecation for default case statement followed by semicolon not
1010
being emitted. (theodorejb)
11+
. Fixed bug GH-20177 (Accessing overridden private property in
12+
get_object_vars() triggers assertion error). (ilutov)
1113

1214
- DOM:
1315
. Fix getNamedItemNS() incorrect namespace check. (nielsdos)

Zend/tests/gh20177.phpt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
GH-20177: Access overridden private property in get_object_vars()
3+
--FILE--
4+
<?php
5+
6+
class A {
7+
private $prop = 'A::$prop';
8+
9+
public function __construct() {
10+
var_dump(get_object_vars($this));
11+
}
12+
}
13+
14+
class B extends A {
15+
protected $prop = 'B::$prop';
16+
}
17+
18+
new B;
19+
20+
?>
21+
--EXPECT--
22+
array(1) {
23+
["prop"]=>
24+
string(8) "A::$prop"
25+
}

Zend/zend_object_handlers.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,11 @@ ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_st
566566
return FAILURE;
567567
}
568568
} else {
569+
/* We were looking for a protected property but found a private one
570+
* belonging to the parent class. */
571+
if (property_info->flags & ZEND_ACC_PRIVATE) {
572+
return FAILURE;
573+
}
569574
ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
570575
}
571576
return SUCCESS;

0 commit comments

Comments
 (0)