Skip to content

Commit 4d5d779

Browse files
committed
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.
1 parent 76c8d79 commit 4d5d779

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
--TEST--
2+
Foreach over object with shadowed private property
3+
--FILE--
4+
<?php
5+
6+
class Test {
7+
private $prop = "Test";
8+
9+
function run() {
10+
foreach ($this as $k => $v) {
11+
echo "$k => $v\n";
12+
}
13+
var_dump(get_object_vars($this));
14+
}
15+
}
16+
class Test2 extends Test {
17+
public $prop = "Test2";
18+
}
19+
20+
(new Test2)->run();
21+
22+
?>
23+
--EXPECT--
24+
prop => Test
25+
array(1) {
26+
["prop"]=>
27+
string(4) "Test"
28+
}

Zend/zend_object_handlers.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -558,16 +558,16 @@ ZEND_API int zend_check_property_access(zend_object *zobj, zend_string *prop_inf
558558
} else {
559559
ZEND_ASSERT(property_info->flags & ZEND_ACC_PROTECTED);
560560
}
561+
return SUCCESS;
561562
} else {
562563
property_info = zend_get_property_info(zobj->ce, prop_info_name, 1);
563564
if (property_info == NULL) {
564565
return SUCCESS;
565566
} else if (property_info == ZEND_WRONG_PROPERTY_INFO) {
566567
return FAILURE;
567568
}
568-
ZEND_ASSERT(property_info->flags & ZEND_ACC_PUBLIC);
569+
return (property_info->flags & ZEND_ACC_PUBLIC) ? SUCCESS : FAILURE;
569570
}
570-
return SUCCESS;
571571
}
572572
/* }}} */
573573

0 commit comments

Comments
 (0)