diff --git a/Zend/tests/gh20177.phpt b/Zend/tests/gh20177.phpt new file mode 100644 index 00000000000..fd69460067f --- /dev/null +++ b/Zend/tests/gh20177.phpt @@ -0,0 +1,25 @@ +--TEST-- +GH-20177: Access overridden private property in get_object_vars() +--FILE-- + +--EXPECT-- +array(1) { + ["prop"]=> + string(8) "A::$prop" +} diff --git a/Zend/zend_object_handlers.c b/Zend/zend_object_handlers.c index 5d1ec65ccda..17676e8edea 100644 --- a/Zend/zend_object_handlers.c +++ b/Zend/zend_object_handlers.c @@ -566,6 +566,11 @@ ZEND_API zend_result zend_check_property_access(const zend_object *zobj, zend_st return FAILURE; } } else { + /* We were looking for a protected property but found a private one + * belonging to the parent class. */ + if (property_info->flags & ZEND_ACC_PRIVATE) { + return FAILURE; + } ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED); } return SUCCESS;