ID: 33171 Updated by: [EMAIL PROTECTED] Reported By: ladislav dot prosek at matfyz dot cz -Status: Verified +Status: Closed Bug Type: Zend Engine 2 problem Operating System: Win XP Pro SP2 PHP Version: 5.0.4 New Comment:
Fixed in CVS HEAD and PHP_5_0. Previous Comments: ------------------------------------------------------------------------ [2005-05-28 14:39:46] ladislav dot prosek at matfyz dot cz Description: ------------ Using foreach on $this results in enumerating not only visible fields (i.e. public and protected field declared along the inheritance hierarchy + private fields declared in current class) but also all private fields declared along the inheritance hierarchy. This is wrong since those fields are not visible and should not be accessible. By the way, the foreach documentation page still says "foreach works only on arrays...". Perhaps you should consider updating it ;-) Reproduce code: --------------- class A { private $c = "A's c"; } class B extends A { private $c = "B's c"; public function go() { foreach ($this as $key => $val) { echo "$key => $val\n"; } } }; $x = new B; $x->go(); Expected result: ---------------- c => B's c Actual result: -------------- c => B's c c => A's c ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33171&edit=1