Skip to content
Permalink
Browse files

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.
  • Loading branch information
nikic committed Oct 10, 2018
1 parent 76c8d79 commit 4d5d77904e9e4dc52236ec5416d1ddfef9b3911c
Showing with 30 additions and 2 deletions.
  1. +28 −0 Zend/tests/foreach_shadowed_property.phpt
  2. +2 −2 Zend/zend_object_handlers.c
@@ -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,16 +558,16 @@ 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) {
return SUCCESS;
} 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;
}
/* }}} */

0 comments on commit 4d5d779

Please sign in to comment.
You can’t perform that action at this time.