Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Zend/tests/gh20177.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
GH-20177: Access overridden private property in get_object_vars()
--FILE--
<?php

class A {
private $prop = 'A::$prop';

public function __construct() {
var_dump(get_object_vars($this));
}
}

class B extends A {
protected $prop = 'B::$prop';
}

new B;

?>
--EXPECT--
array(1) {
["prop"]=>
string(8) "A::$prop"
}
7 changes: 7 additions & 0 deletions Zend/zend_object_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_st
return FAILURE;
}
} else {
/* The property we found may be private if we have a private parent
* property and a protected child property, and we're accessing the
* property from the parent's scope. In that case we want to access
* the parent property, not child property. */
Comment on lines +531 to +534
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to have a shorter comment in the spirit of the two comments above.

"we are looking for a protected prop but found a private one of the same name but parent class"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I simplified the comment before merging.

if (property_info->flags & ZEND_ACC_PRIVATE) {
return FAILURE;
}
ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
}
return SUCCESS;
Expand Down
Loading