|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-06-06 09:52 UTC] dmitry@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 04:00:02 2025 UTC |
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