Re: Inconsistencies when accessing protected members

From: Date: Thu, 27 Mar 2008 18:29:30 +0000
Subject: Re: Inconsistencies when accessing protected members
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-36620@lists.php.net to get a copy of this message
Hi!
- 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.
Which means there exists A::f(), B1::f() and B2::f() (being the same as A::f()), all of which are protected.
- 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.
A::f() is visible from B2, and B1 can not have access to f() more restricted than A since it's violate the Liskov principle - objects of B1 couldn't be used the same way as objects of A in all contexts. Look at this also this way: suppose we had no B1::f. Then if we call f() from B2, we always get A::f() which is protected, so it works. Now we copy A::f definition to B1 verbatim - with same access, same everything. Should now code that calls f() on B1 start failing? -- Stanislav Malyshev, Zend Software Architect stas@zend.com http://www.zend.com/ (408)253-8829 MSN: stas@zend.com

« previous php.internals (#36620) next »