Skip to content

Commit 02c67b4

Browse files
committed
Fix accessing of overridden private property in get_object_vars()
Fixes phpGH-20177 Closes phpGH-20182
1 parent 75b770e commit 02c67b4

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
@@ -7,6 +7,8 @@ PHP NEWS
77
. Fixed bug GH-20073 (Assertion failure in WeakMap offset operations on
88
reference). (nielsdos)
99
. Fixed bug GH-19844 (Don't bail when closing resources on shutdown). (ilutov)
10+
. Fixed bug GH-20177 (Accessing overridden private property in
11+
get_object_vars() triggers assertion error). (ilutov)
1012

1113
- DOM:
1214
. 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
@@ -528,6 +528,11 @@ ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_st
528528
return FAILURE;
529529
}
530530
} else {
531+
/* We were looking for a protected property but found a private one
532+
* belonging to the parent class. */
533+
if (property_info->flags & ZEND_ACC_PRIVATE) {
534+
return FAILURE;
535+
}
531536
ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
532537
}
533538
return SUCCESS;

0 commit comments

Comments
 (0)