svn: /phpdoc/en/trunk/language/oop5/ traits.xml
| From: | Justin Martin | Date: | Wed, 20 Jul 2011 22:36:10 +0000 |
| Subject: | svn: /phpdoc/en/trunk/language/oop5/ traits.xml | ||
| Groups: | php.doc.cvs | ||
| Request: | Send a blank email to doc-cvs+get-8519@lists.php.net to get a copy of this message | ||
frozenfire Wed, 20 Jul 2011 22:36:10 +0000
Revision: http://svn.php.net/viewvc?view=revision&revision=313491
Log:
Added descriptions of trait composition, trait abstraction and static trait members.
Moved examples inline with each respective section.
Changed paths:
U phpdoc/en/trunk/language/oop5/traits.xml
Modified: phpdoc/en/trunk/language/oop5/traits.xml
===================================================================
--- phpdoc/en/trunk/language/oop5/traits.xml 2011-07-20 22:11:45 UTC (rev 313490)
+++ phpdoc/en/trunk/language/oop5/traits.xml 2011-07-20 22:36:10 UTC (rev 313491)
@@ -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 @@
]]>
</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 @@
]]>
</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 @@
]]>
</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 @@
]]>
</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 @@
]]>
</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 @@
]]>
</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 @@
]]>
</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 @@
]]>
</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 @@
</programlisting>
</example>
</sect2>
+
</sect1>
<!-- Keep this comment at the end of the file
@@ -355,5 +379,5 @@
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
-->