Index: oop5.xml =================================================================== RCS file: /repository/phpdoc/en/language/oop5.xml,v retrieving revision 1.13 diff -u -p -r1.13 oop5.xml --- oop5.xml 20 Jun 2007 22:24:12 -0000 1.13 +++ oop5.xml 21 Oct 2007 00:47:30 -0000 @@ -30,6 +30,7 @@ &language.oop5.object-comparison; &language.oop5.reflection; &language.oop5.typehinting; + &language.oop5.late-static-bindings; + + Late Static Bindings + + As of PHP 5.3.0, PHP implements a feature called late static bindings which + can be used to reference the called class in a context of static inheritance. + + + + This feature was named "late static bindings" with an internal perspective in + mind. "Late binding" comes from the fact that static:: + will no longer be resolved using the class where the method is defined but + it will rather be computed using runtime information. + + It was also called a "static binding" as it can be used for (but is not + limited to) static method calls. + + + + Limitations of <literal>self::</literal> + + Static references to the current class like self:: or + __CLASS__ are resolved using the class in which the + function belongs, as in where it was defined: + + + <literal>self::</literal> usage + + +]]> + + &example.outputs; + + + + + + + + + Late Static Bindings' usage + + + Late static bindings tries to solve that limitation by introducing a + keyword that references the class that was initially called at runtime. + Basically, a keyword that would allow you to reference + B from test() in the previous + example. It was decided not to introduce a new keyword but rather use + static that was already reserved. + + + + <literal>static::</literal> simple usage + + +]]> + + &example.outputs; + + + + + + + static:: does not work like $this for + static methods! $this-> follows the rules of + inheritance while static:: doesn't. This difference is + detailed later on this manual page. + + + + <literal>static::</literal> usage in a non-static context + +test(); + +?> +]]> + + &example.outputs; + + + + + + + Late static bindings' reslution will stop at a fully resolved static call with no fallback. + + + Fully resolved static calls + + +]]> + + &example.outputs; + + + + + + + + Edge cases + + There are lots of different ways to trigger a method call in PHP, like + callbacks or magic methods. As late static bindings base their resolution + on runtime information, it might give unexpected results in so-called edge + cases. + + + Late static bindings inside magic methods + +foo; +?> +]]> + + &example.outputs; + + + + + + +