cvs: phpdoc /en/language/oop5 late-static-bindings.xml

From: Date: Thu, 25 Dec 2008 17:24:43 +0000
Subject: cvs: phpdoc /en/language/oop5 late-static-bindings.xml
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-2823@lists.php.net to get a copy of this message
sammywg Thu Dec 25 17:24:43 2008 UTC Modified files: /phpdoc/en/language/oop5 late-static-bindings.xml Log: fix linebreak http://cvs.php.net/viewvc.cgi/phpdoc/en/language/oop5/late-static-bindings.xml?r1=1.3&r2=1.4&diff_format=u Index: phpdoc/en/language/oop5/late-static-bindings.xml diff -u phpdoc/en/language/oop5/late-static-bindings.xml:1.3 phpdoc/en/language/oop5/late-static-bindings.xml:1.4 --- phpdoc/en/language/oop5/late-static-bindings.xml:1.3 Tue Jul 29 00:29:44 2008 +++ phpdoc/en/language/oop5/late-static-bindings.xml Thu Dec 25 17:24:43 2008 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1"?> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> <sect1 xml:id="language.oop5.late-static-bindings" xmlns="http://docbook.org/ns/docbook"> <title>Late Static Bindings</title> <para> @@ -9,19 +9,19 @@ <para> This feature was named "late static bindings" with an internal perspective in - mind. "Late binding" comes from the fact that <literal>static::</literal> - will no longer be resolved using the class where the method is defined but + mind. "Late binding" comes from the fact that <literal>static::</literal> + 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. </para> <sect2 xml:id="language.oop5.late-static-bindings.self"> <title>Limitations of <literal>self::</literal></title> <para> - Static references to the current class like <literal>self::</literal> or - <literal>__CLASS__</literal> are resolved using the class in which the + Static references to the current class like <literal>self::</literal> or + <literal>__CLASS__</literal> are resolved using the class in which the function belongs, as in where it was defined: </para> <example> @@ -34,18 +34,18 @@ 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(); -?> +?> ]]> </programlisting> &example.outputs; @@ -57,16 +57,16 @@ </example> </sect2> - + <sect2 xml:id="language.oop5.late-static-bindings.usage"> <title>Late Static Bindings' usage</title> <para> - 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 - <literal>B</literal> from <literal>test()</literal> 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 + <literal>B</literal> from <literal>test()</literal> in the previous + example. It was decided not to introduce a new keyword but rather use <literal>static</literal> that was already reserved. </para> @@ -80,18 +80,18 @@ 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(); -?> +?> ]]> </programlisting> &example.outputs; @@ -104,7 +104,7 @@ <note> <para> <literal>static::</literal> does not work like <literal>$this</literal> for - static methods! <literal>$this-></literal> follows the rules of + static methods! <literal>$this-></literal> follows the rules of inheritance while <literal>static::</literal> doesn't. This difference is detailed later on this manual page. </para> @@ -140,7 +140,7 @@ $o = new TestChild; $o->test(); -?> +?> ]]> </programlisting> &example.outputs; @@ -153,7 +153,10 @@ </example> <note> <para> - Late static bindings' resolution will stop at a fully resolved static call with no fallback. On the other hand, static calls using keywords like <literal>parent::</literal> or <literal>self::</literal> 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 + <literal>parent::</literal> or <literal>self::</literal> will forward the + calling information. </para> <example> <title>Forwarding and non-forwarding calls</title> @@ -164,7 +167,7 @@ public static function foo() { static::who(); } - + public static function who() { echo __CLASS__."\n"; } @@ -188,7 +191,7 @@ } C::test(); -?> +?> ]]> </programlisting> &example.outputs; @@ -205,10 +208,10 @@ <sect2 xml:id="language.oop5.late-static-bindings.edge-cases"> <title>Edge cases</title> <para> - 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. </para> <example> <title>Late static bindings inside magic methods</title> @@ -235,7 +238,7 @@ $b = new B; $b->foo; -?> +?> ]]> </programlisting> &example.outputs;

« previous php.doc.cvs (#2823) next »