From 7ee2349a71faecb4e08eccda1734e3dec76cb7d0 Mon Sep 17 00:00:00 2001 From: Justin Martin <frozenfire@php.net> Date: Wed, 20 Jul 2011 22:36:10 +0000 Subject: [PATCH] Added descriptions of trait composition, trait abstraction and static trait members. Moved examples inline with each respective section. git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@313491 c90b9560-bf6c-de11-be94-00142212c4b1 --- language/oop5/traits.xml | 113 ++++++++++++++++++++++++--------------- 1 file changed, 69 insertions(+), 44 deletions(-) diff --git a/language/oop5/traits.xml b/language/oop5/traits.xml index b8787334a0..3929988e1a 100644 --- a/language/oop5/traits.xml +++ b/language/oop5/traits.xml @@ -19,40 +19,7 @@ requiring inheritance. </para> - <sect2 xml:id="language.oop5.traits.precedence"> - <title>Precedence</title> - <para> - An inherited member from a base class is overridden by a member inserted - by a Trait. The precedence order is that members from the current class - override Trait methods, which in return override inherited methods. - </para> - </sect2> - - <sect2 xml:id="language.oop5.traits.multiple"> - <title>Multiple Traits</title> - <para> - Multiple Traits can be inserted into a class by listing them in the use - statement, separated by commas. - </para> - </sect2> - - <sect2 xml:id="language.oop5.traits.conflict"> - <title>Conflict Resolution</title> - <para> - If two Traits insert a member by the same name, a fatal error is produced, - if the conflict is not explicitly resolved. - </para> - <para> - To resolve conflicted naming among Traits, one can use the <literal>insteadof</literal> - operator to explicitly define the precedence between said Traits. Or, - one can use the <literal>as</literal> operator to alias the conflicting - member name(s). - </para> - </sect2> - - <sect2 xml:id="language.oop5.traits.examples"> - &reftitle.examples; - <example xml:id="language.oop5.traits.examples.ex1"> + <example xml:id="language.oop5.traits.basicexample"> <title>Trait example</title> <programlisting role="php"> <![CDATA[ @@ -75,7 +42,15 @@ class ezcReflectionFunction extends ReflectionFunction { ]]> </programlisting> </example> - <example xml:id="language.oop5.traits.examples.ex2"> + + <sect2 xml:id="language.oop5.traits.precedence"> + <title>Precedence</title> + <para> + An inherited member from a base class is overridden by a member inserted + by a Trait. The precedence order is that members from the current class + override Trait methods, which in return override inherited methods. + </para> + <example xml:id="language.oop5.traits.precedence.examples.ex1"> <title>Precedence Order Example</title> <para> An inherited method from a base class is overridden by the @@ -116,8 +91,8 @@ Hello World! ]]> </screen> </example> - <example xml:id="language.oop5.traits.examples.ex3"> - <title>Precedence Order Example #2</title> + <example xml:id="language.oop5.traits.precedence.examples.ex2"> + <title>Alternate Precedence Order Example</title> <programlisting role="php"> <![CDATA[ <?php @@ -146,7 +121,15 @@ Hello Universe! ]]> </screen> </example> - <example xml:id="language.oop5.traits.examples.ex4"> + </sect2> + + <sect2 xml:id="language.oop5.traits.multiple"> + <title>Multiple Traits</title> + <para> + Multiple Traits can be inserted into a class by listing them in the use + statement, separated by commas. + </para> + <example xml:id="language.oop5.traits.multiple.ex1"> <title>Multiple Traits Usage</title> <programlisting role="php"> <![CDATA[ @@ -184,7 +167,21 @@ Hello World! ]]> </screen> </example> - <example xml:id="language.oop5.traits.examples.ex5"> + </sect2> + + <sect2 xml:id="language.oop5.traits.conflict"> + <title>Conflict Resolution</title> + <para> + If two Traits insert a member by the same name, a fatal error is produced, + if the conflict is not explicitly resolved. + </para> + <para> + To resolve conflicted naming among Traits, one can use the <literal>insteadof</literal> + operator to explicitly define the precedence between said Traits. Or, + one can use the <literal>as</literal> operator to alias the conflicting + member name(s). + </para> + <example xml:id="language.oop5.traits.conflict.ex1"> <title>Conflict Resolution</title> <programlisting role="php"> <![CDATA[ @@ -225,7 +222,16 @@ class Aliased_Talker { ]]> </programlisting> </example> - <example xml:id="language.oop5.traits.examples.ex6"> + </sect2> + + <sect2 xml:id="language.oop5.traits.composition"> + <title>Traits Composed from Traits</title> + <para> + Just as classes can make use of traits, so can other traits. By using one + or more traits in a trait definition, it can be composed partially or + entirely of the members defined in those other traits. + </para> + <example xml:id="language.oop5.traits.composition.ex1"> <title>Traits Composed from Traits</title> <programlisting role="php"> <![CDATA[ @@ -263,7 +269,15 @@ Hello World! ]]> </screen> </example> - <example xml:id="language.oop5.traits.examples.ex7"> + </sect2> + + <sect2 xml:id="language.oop5.traits.abstract"> + <title>Abstract Trait Members</title> + <para> + Traits support the use of abstract methods in order to impose requirements + upon the exhibiting class. + </para> + <example xml:id="language.oop5.traits.abstract.ex1"> <title>Express Requirements by Abstract Methods</title> <programlisting role="php"> <![CDATA[ @@ -289,7 +303,16 @@ class MyHelloWorld { ]]> </programlisting> </example> - <example xml:id="language.oop5.traits.examples.ex8"> + </sect2> + + <sect2 xml:id="language.oop5.traits.static"> + <title>Static Trait Members</title> + <para> + Static variables can be referred to in trait methods, but cannot be + defined by the trait. Traits can, however, define static methods for + the exhibiting class. + </para> + <example xml:id="language.oop5.traits.static.ex1"> <title>Static Variables</title> <programlisting role="php"> <![CDATA[ @@ -316,7 +339,7 @@ class MyHelloWorld { ]]> </programlisting> </example> - <example xml:id="language.oop5.traits.examples.ex9"> + <example xml:id="language.oop5.traits.static.ex2"> <title>Static Methods</title> <programlisting role="php"> <![CDATA[ @@ -335,6 +358,7 @@ class MyHelloWorld { </programlisting> </example> </sect2> + </sect1> <!-- Keep this comment at the end of the file @@ -355,4 +379,5 @@ sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml -vi: ts=1 sw=1 --> +vi: ts=1 sw=1 +-->