Re: Inconsistencies when accessing protected members
| From: | Robin Fernandes | Date: | Thu, 27 Mar 2008 10:59:51 +0000 |
| Subject: | Re: Inconsistencies when accessing protected members | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-36612@lists.php.net to get a copy of this message | ||
Hi all, thanks for thinking about this.
On 26/03/2008, Marcus Boerger <helly@php.net> wrote:
> On 26/03/2008, Alexey Zakhlestin <indeyets@gmail.com> wrote:
>
> > use case for "protected" is similiar, but relates to cases when you
> > have hierarchy of classes, which still have some common functionality,
> > which might be usable for multi-instance operations
>
> Thanks. This is the exact way we see this. Anything that violates this rule
> is a bug.
Ok, good. So to get back to the original question
(http://turl.ca/kfanjo), in the following case, should B1::f() be
visible from B2 in the code example below? Note that:
- B1 and B2 both extend A. B2 is neither an ancestor nor a
descendant of B1, but I suppose they could be considered to be part of
the same class hierarchy because they are siblings.
- f() is declared as protected in A and B1, but not declared at all in B2.
- The docs state: "Protected limits access to inherited and parent
classes (and to the class that defines the item)" -
http://php.net/manual/en/language.oop5.visibility.php
.
Currently, B1::f() is visible from B2.
--> If this is a bug, Felipe's patch
(http://ecl.mediain.com.br/diff/protected.diff) fixes the issue. Let's
commit it! :)
--> If this is not a bug then the docs need to be clarified.
Furthermore, callbacks, is_callable(), lookups to the clone & destruct
magic methods and possibly property access should all be changed,
because they currently do not adhere to this rule (as illustrated in
the code snippets in http://turl.ca/kfanjo ).
The code:
<?php
class A {
static protected function f() {return 'In A::f';}
}
class B1 extends A {
static protected function f() {return 'In B1::f';}
}
class B2 extends A {
static public function test() {echo B1::f();} // Currently, this works.
}
B2::test();
?>
Regards,
Robin.