ID: 50892
Updated by: colder@php.net
Reported By: EdwardDrapkin at gmail dot com
-Status: Bogus
+Status: Open
Bug Type: Class/Object related
Operating System: Irrelevant
PHP Version: 5.3.1
New Comment:
At a second glance, it really looks like it is wrong.
The visibility check should also be based on the object from which the
properties are read.
As for my "it works that way in Java" argument, it contradicts the java
specifications:
http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.6.2.1
and hence is invalid. (Thanks oorza for pointing that out)
There is no design ground to accept that, it is a bug. The question
that
remains is: is it worth to fix BC-wise?
Previous Comments:
------------------------------------------------------------------------
[2010-02-01 14:23:51] johannes@php.net
That's a fundamental part of a class based inheritance system.Changing
this won't only affect BC but also the fundamental design.
------------------------------------------------------------------------
[2010-02-01 14:15:28] colder@php.net
Even though it feels odd, it's how the checks are currently designed.
The same applies to i.e. Java. I guess we cannot change things here
without introducing nasty and hard to track BC breaks.
------------------------------------------------------------------------
[2010-02-01 13:59:30] EdwardDrapkin at gmail dot com
I also wanted to point out I spoke to ekneuss at length about this
issue, in IRC, and he confirmed it.
------------------------------------------------------------------------
[2010-02-01 13:57:29] EdwardDrapkin at gmail dot com
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?
------------------------------------------------------------------------
[2010-02-01 09:32:01] jani@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
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
http://bugs.php.net/50892
--
Edit this bug report at http://bugs.php.net/?id=50892&edit=1