mirror of
https://github.com/php/php-src.git
synced 2026-04-14 19:41:05 +02:00
Fix foreach/get_object_vars for shadowed properties
If we are in a scope where the shadowed private property is visible, the shadowing public property should not be visible.
This commit is contained in:
28
Zend/tests/foreach_shadowed_property.phpt
Normal file
28
Zend/tests/foreach_shadowed_property.phpt
Normal file
@@ -0,0 +1,28 @@
|
||||
--TEST--
|
||||
Foreach over object with shadowed private property
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
class Test {
|
||||
private $prop = "Test";
|
||||
|
||||
function run() {
|
||||
foreach ($this as $k => $v) {
|
||||
echo "$k => $v\n";
|
||||
}
|
||||
var_dump(get_object_vars($this));
|
||||
}
|
||||
}
|
||||
class Test2 extends Test {
|
||||
public $prop = "Test2";
|
||||
}
|
||||
|
||||
(new Test2)->run();
|
||||
|
||||
?>
|
||||
--EXPECT--
|
||||
prop => Test
|
||||
array(1) {
|
||||
["prop"]=>
|
||||
string(4) "Test"
|
||||
}
|
||||
@@ -558,6 +558,7 @@ ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_inf
|
||||
} else {
|
||||
ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
|
||||
}
|
||||
return SUCCESS;
|
||||
} else {
|
||||
property_info = zend_get_property_info(zobj->ce, prop_info_name, 1);
|
||||
if (property_info == NULL) {
|
||||
@@ -565,9 +566,8 @@ ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_inf
|
||||
} else if (property_info == ZEND_WRONG_PROPERTY_INFO) {
|
||||
return FAILURE;
|
||||
}
|
||||
ZEND_ASSERT(property_info->flags & ZEND_ACC_PUBLIC);
|
||||
return (property_info->flags & ZEND_ACC_PUBLIC) ? SUCCESS : FAILURE;
|
||||
}
|
||||
return SUCCESS;
|
||||
}
|
||||
/* }}} */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user