ID: 50892 User updated by: EdwardDrapkin at gmail dot com Reported By: EdwardDrapkin at gmail dot com Status: Bogus Bug Type: Class/Object related Operating System: Irrelevant PHP Version: 5.3.1 New Comment:
I did "RTFM" and I understand that protected members are not SUPPOSED TO BE ABLE to be accessed from anything but "within the class itself and by inherited and parent classes." The bug is that, when the calling scope resolves and LOOKS LIKE the correct scope because it is an inherited class, but is a _different inherited class_ of the same parent object in which the protected member was declared, the engine allows access to protected members from OUTSIDE THE CLASS. In the example, both "bar" and "kid" extend foo, but "kid" should NOT have access to bar's protected members, but it does, but its resolving scope looks similar to the correct scope that would need to resolve. This isn't an RTFM issue, it's a legitimate bug. Did you read the reproduce code? Previous Comments: ------------------------------------------------------------------------ [2010-02-01 09:32:01] j...@php.net RTFM: "Members declared protected can be accessed only within the class itself and by inherited and parent classes." http://php.net/manual/en/language.oop5.visibility.php ------------------------------------------------------------------------ [2010-01-31 20:21:11] EdwardDrapkin at gmail dot com Description: ------------ When you have two classes that extend the same base class, if the protected members are declared in the base class, they are visible to each other. Because the class variables are protected, they should not be available to other classes, even if they share the same parent (but are of different types themselves)! Reproduce code: --------------- <?php class foo { public $public = "a"; private $private = "b"; protected $protected = "protected"; } class bar extends foo { } class kid extends foo { public function test() { $b = new bar(); var_dump(get_object_vars($b)); var_dump($b->protected); } } $k = new kid(); $k->test(); Expected result: ---------------- array(1) { ["public"]=> string(1) "a" } Visibility error. Actual result: -------------- array(2) { ["public"]=> string(1) "a" ["protected"]=> string(9) "protected" } string(9) "protected" ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=50892&edit=1