diff --git a/language/oop5/late-static-bindings.xml b/language/oop5/late-static-bindings.xml index 769415975a..e14cb5516d 100644 --- a/language/oop5/late-static-bindings.xml +++ b/language/oop5/late-static-bindings.xml @@ -1,5 +1,5 @@ - + Late Static Bindings @@ -9,19 +9,19 @@ 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 + 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 + 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 + 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: @@ -34,18 +34,18 @@ class A { echo __CLASS__; } public static function test() { - self::who(); - } -} + self::who(); + } +} -class B extends A { +class B extends A { public static function who() { echo __CLASS__; - } -} + } +} B::test(); -?> +?> ]]> &example.outputs; @@ -57,16 +57,16 @@ A - + Late Static Bindings' usage - Late static bindings tries to solve that limitation by introducing a + 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 + 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. @@ -80,18 +80,18 @@ class A { echo __CLASS__; } public static function test() { - static::who(); // Here comes Late Static Bindings - } -} + static::who(); // Here comes Late Static Bindings + } +} -class B extends A { +class B extends A { public static function who() { echo __CLASS__; - } -} + } +} B::test(); -?> +?> ]]> &example.outputs; @@ -104,7 +104,7 @@ B static:: does not work like $this for - static methods! $this-> follows the rules of + static methods! $this-> follows the rules of inheritance while static:: doesn't. This difference is detailed later on this manual page. @@ -140,7 +140,7 @@ class TestParent { $o = new TestChild; $o->test(); -?> +?> ]]> &example.outputs; @@ -153,7 +153,10 @@ TestParent - Late static bindings' resolution will stop at a fully resolved static call with no fallback. On the other hand, static calls using keywords like parent:: or self:: will forward the calling information. + Late static bindings' resolution will stop at a fully resolved static call + with no fallback. On the other hand, static calls using keywords like + parent:: or self:: will forward the + calling information. Forwarding and non-forwarding calls @@ -164,7 +167,7 @@ class A { public static function foo() { static::who(); } - + public static function who() { echo __CLASS__."\n"; } @@ -188,7 +191,7 @@ class C extends B { } C::test(); -?> +?> ]]> &example.outputs; @@ -205,10 +208,10 @@ C Edge cases - There are lots of different ways to trigger a method call in PHP, like + 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. + on runtime information, it might give unexpected results in so-called edge + cases. Late static bindings inside magic methods @@ -235,7 +238,7 @@ class B extends A { $b = new B; $b->foo; -?> +?> ]]> &example.outputs;