rfc:protectedlookup
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:protectedlookup [2008/06/03 13:36] – robinf | rfc:protectedlookup [2008/06/03 16:09] – add links to tests & patch for option 2 (still being tested) robinf | ||
---|---|---|---|
Line 177: | Line 177: | ||
Remove new rule: remove calls to zend_get_function_root_class(). | Remove new rule: remove calls to zend_get_function_root_class(). | ||
=== Patch === | === Patch === | ||
- | [[http:// | + | * [[http:// |
+ | * [[http:// | ||
=== Pros === | === Pros === | ||
* Simple code change | * Simple code change | ||
Line 211: | Line 212: | ||
If option 1 is dismissed due to the violation of LSP, it follows that the current rules for property access, callbacks, '' | If option 1 is dismissed due to the violation of LSP, it follows that the current rules for property access, callbacks, '' | ||
=== Patch === | === Patch === | ||
- | To do. | + | * [[http:// |
+ | * [[http:// | ||
=== Pros === | === Pros === | ||
* Respects the Liskov Substitution Principle. | * Respects the Liskov Substitution Principle. | ||
Line 218: | Line 220: | ||
* The protected modifier loses its intuitive/ | * The protected modifier loses its intuitive/ | ||
| | ||
+ | |||
==== Option 3 ==== | ==== Option 3 ==== | ||
This approach is similar to option 2, but modifies the new rule slightly so as to preserve the intuitive meaning of the protected modifier. Lookups of protected members on sibling classes fall back to the declaration from the common ancestor class, if available. To illustrate: | This approach is similar to option 2, but modifies the new rule slightly so as to preserve the intuitive meaning of the protected modifier. Lookups of protected members on sibling classes fall back to the declaration from the common ancestor class, if available. To illustrate: | ||
Line 243: | Line 246: | ||
</ | </ | ||
=== Patch === | === Patch === | ||
- | | + | * Patch to do. |
+ | * [[http:// | ||
=== Pros === | === Pros === | ||
* Respects the Liskov Substitution Principle. | * Respects the Liskov Substitution Principle. | ||
Line 249: | Line 253: | ||
=== Cons === | === Cons === | ||
* Non-trivial code change | * Non-trivial code change | ||
- | * Possibly confusing at first, as code that reads C1::f() may in fact result in an invocation of P::f(). | + | * Possibly confusing at first, as code that reads C1::f() may in fact result in an invocation of P:: |
+ | <code php> | ||
+ | <?php | ||
+ | // Class P declares some private members. | ||
+ | class P { | ||
+ | private function f() { echo ' | ||
+ | public static function test() { | ||
+ | $c = new C; | ||
+ | $c-> | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // Class C1 re-declares the " | ||
+ | class C extends P { | ||
+ | private function f() { echo ' | ||
+ | } | ||
+ | |||
+ | P:: | ||
+ | ?> | ||
+ | </ | ||
+ | |||
Line 293: | Line 318: | ||
echo $liskov-> | echo $liskov-> | ||
echo " | echo " | ||
- | echo C::$sa . " | + | echo $class::$sa . " |
} | } | ||
} | } |
rfc/protectedlookup.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1