Skip to content

Commit f5fc755

Browse files
committed
Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3: Fix accessing of overridden private property in get_object_vars()
2 parents b0a3f7a + 02c67b4 commit f5fc755

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
@@ -9,6 +9,8 @@ PHP NEWS
99
. Fixed bug GH-20085 (Assertion failure when combining lazy object
1010
get_properties exception with foreach loop). (nielsdos)
1111
. Fixed bug GH-19844 (Don't bail when closing resources on shutdown). (ilutov)
12+
. Fixed bug GH-20177 (Accessing overridden private property in
13+
get_object_vars() triggers assertion error). (ilutov)
1214

1315
- DOM:
1416
. Partially fixed bug GH-16317 (DOM classes do not allow

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
@@ -561,6 +561,11 @@ ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_st
561561
return FAILURE;
562562
}
563563
} else {
564+
/* We were looking for a protected property but found a private one
565+
* belonging to the parent class. */
566+
if (property_info->flags & ZEND_ACC_PRIVATE) {
567+
return FAILURE;
568+
}
564569
ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
565570
}
566571
return SUCCESS;

0 commit comments

Comments
 (0)