com php-langspec: Allow trait uses between other class/trait members: spec/14-classes.md spec/16-traits.md

[email protected] (Stanislav Malyshev) Tue, 29 Dec 2015 17:44:58 +0000
Newsgroups php.standards.cvs
Message-ID <[email protected]>
Commit:    5a4f3305ec3725b6e8e523d35edb631de1792326
Author:    Nikita Popov <[email protected]>         Tue, 29 Dec 2015 18:44:58 +0100
Parents:   25b46b2a272273d73963a81d14dc7ab72891555a
Branches:  master

Link:       http://git.php.net/?p=php-langspec.git;a=commitdiff;h=5a4f3305ec3725b6e8e523d35edb631de1792326

Log:
Allow trait uses between other class/trait members

I've separated out trait-use-clauses into a separate heading to
make this somewhat clean.

Changed paths:
  M  spec/14-classes.md
  M  spec/16-traits.md


Diff:
diff --git a/spec/14-classes.md b/spec/14-classes.md
index 7334f96..4b1ebcc 100644
--- a/spec/14-classes.md
+++ b/spec/14-classes.md
@@ -60,7 +60,7 @@ While PHP supports *anonymous class types*, such a type cannot be declared using
 
 <pre>
   <i>class-declaration:</i>
-    <i>class-modifier<sub>opt</sub></i>  class  <i>name   class-base-clause<sub>opt</sub>  class-interface-clause<sub>opt</sub></i>   {   <i>trait-use-clauses<sub>opt</sub>   class-member-declarations<sub>opt</sub></i> }
+    <i>class-modifier<sub>opt</sub></i>  class  <i>name   class-base-clause<sub>opt</sub>  class-interface-clause<sub>opt</sub></i>   {   class-member-declarations<sub>opt</sub></i> }
 
   <i>class-modifier:</i>
     abstract
@@ -77,7 +77,6 @@ While PHP supports *anonymous class types*, such a type cannot be declared using
 **Defined elsewhere**
 
 * [*class-member-declarations*](#class-members)
-* [*trait-use-clauses*](16-traits.md#trait-declarations)
 
 **Constraints**
 
@@ -138,8 +137,6 @@ inherits all the members from the base class.
 The optional *class-interface-clause* specifies the one or more
 interfaces that are implemented by the class being defined.
 
-A class can use one or more traits via a [*trait-use-clauses*](16-traits.md#general).
-
 **Examples**
 
 ```PHP
@@ -211,6 +208,7 @@ class MyList implements MyCollection
      <i>method-declaration</i>
      <i>constructor-declaration</i>
      <i>destructor-declaration</i>
+     <i>trait-use-clause</i>
 </pre>
 
 **Defined elsewhere**
@@ -220,6 +218,7 @@ class MyList implements MyCollection
 * [*method-declaration*](#methods)
 * [*constructor-declaration*](#constructors)
 * [*destructor-declaration*](#destructors)
+* [*trait-use-clauses*](16-traits.md#trait-uses)
 
 **Semantics**
 
@@ -241,6 +240,8 @@ Some methods have special semantics, such as:
     class is no longer needed.
 -   [Special (or *magic*) methods](#methods-with-special-semantics)
 
+Members can be imported from one or more traits via [*trait-use-clauses*](16-traits.md#general).
+
 The class can also have [dynamic members](#dynamic-members) which are not part of the class definition.
 
 Methods and properties can either be *static* or *instance* members. A
diff --git a/spec/16-traits.md b/spec/16-traits.md
index 90061b7..9cdf9bc 100644
--- a/spec/16-traits.md
+++ b/spec/16-traits.md
@@ -44,8 +44,69 @@ that trait is used.
 
 <pre>
   <i>trait-declaration:</i>
-    trait   <i>name</i>   {   <i>trait-use-clauses<sub>opt</sub>   trait-member-declarations<sub>opt</sub></i>   }
+    trait   <i>name</i>   {   trait-member-declarations<sub>opt</sub></i>   }
 
+  <i>trait-member-declarations:</i>
+    <i>trait-member-declaration</i>
+    <i>trait-member-declarations   trait-member-declaration</i>
+
+  <i>trait-member-declaration:</i>
+    <i>property-declaration</i>
+    <i>method-declaration</i>
+    <i>constructor-declaration</i>
+    <i>destructor-declaration</i>
+    <i>trait-use-clauses</i>
+</pre>
+
+**Defined elsewhere**
+
+* [*property-declaration*](14-classes.md#properties)
+* [*method-declaration*](14-classes.md#methods)
+* [*constructor-declaration*](14-classes.md#constructors)
+* [*destructor-declaration*](14-classes.md#destructors)
+* [*trait-use-clauses*](#trait-uses)
+
+**Semantics**
+
+A *trait-declaration* defines a named set of members, which are made
+available to any class that uses that trait.
+
+Trait names are case-insensitive.
+
+The members of a trait are those specified by its *trait-member-declaration*
+clauses, and members imported from any other traits using *trait-use-clauses*.
+
+A trait may contain the following members:
+
+-   [Properties](14-classes.md#properties) – the variables made available to the class in which the
+    trait is used.
+-   [Methods](14-classes.md#methods) – the computations and actions that can be performed by the
+    class in which the trait is used.
+-   [Constructor](14-classes.md#constructors) – the actions required to initialize an instance of the
+    class in which the trait is used.
+-   [Destructor](14-classes.md#destructors) – the actions to be performed when an instance of the
+    class in which the trait is used is no longer needed.
+
+If a member has no explicit visibility, `public` is assumed.
+
+**Examples**
+
+```PHP
+trait T
+{
+  private $prop1 = 1000;
+  protected static $prop2;
+  var $prop3;
+  public function compute( ... ) { ... }
+  public static function getData( ... ) { ... }
+}
+```
+
+##Trait Uses
+
+**Syntax**
+
+<pre>
   <i>trait-use-clauses:</i>
     <i>trait-use-clause</i>
     <i>trait-use-clauses   trait-use-clause</i>
@@ -81,7 +142,6 @@ that trait is used.
 
 * [*name*](09-lexical-structure.md#names)
 * [*visibility-modifier*](14-classes.md#properties)
-* [*trait-member-declarations*](#trait-members)
 
 **Constraints**
 
@@ -101,16 +161,12 @@ unqualified name.
 
 **Semantics**
 
-A *trait-declaration* defines a named set of members, which are made
-available to any class that uses that trait.
-
-Trait names are case-insensitive.
-
-A *trait-declaration* may also use other traits. This is done via one or
-more *trait-use-clause* items, each of which contains a comma-separated list
-of trait names. A *trait-use-clause* list ends in a semicolon or a
-brace-delimited set of *trait-select-insteadof-clause* and
-*trait-alias-as-clause* statements.
+*trait-use-clauses* can be used as part of *trait-member-declarations*
+or *class-member-declarations* to import members of a trait into a
+different trait or a class. This is done via one or more *trait-use-clause*
+items, each of which contains a comma-separated list of trait names.
+A *trait-use-clause* list ends in a semicolon or a brace-delimited set of
+*trait-select-insteadof-clause* and *trait-alias-as-clause* statements.
 
 A *trait-select-insteadof-clause* allows to avoid name clashes.
 Specifically, the left-hand *name* designates which name to be used from
@@ -145,59 +201,4 @@ trait T4
 }
 ```
 
-##Trait Members
-
-**Syntax**
-
-<pre>
-  <i>trait-member-declarations:</i>
-    <i>trait-member-declaration</i>
-    <i>trait-member-declarations   trait-member-declaration</i>
-
-  <i>trait-member-declaration:</i>
-    <i>property-declaration</i>
-    <i>method-declaration</i>
-    <i>constructor-declaration</i>
-    <i>destructor-declaration</i>
-</pre>
-
-**Defined elsewhere**
-
-* [*property-declaration*](14-classes.md#properties)
-* [*method-declaration*](14-classes.md#methods)
-* [*constructor-declaration*](14-classes.md#constructors)
-* [*destructor-declaration*](14-classes.md#destructors)
-
-**Semantics**
-
-The members of a trait are those specified by its
-*trait-member-declaration* clauses, and the members from any other traits it
-uses.
-
-A trait may contain the following members:
-
--   [Properties](14-classes.md#properties) – the variables made available to the class in which the
-    trait is used.
--   [Methods](14-classes.md#methods) – the computations and actions that can be performed by the
-    class in which the trait is used.
--   [Constructor](14-classes.md#constructors) – the actions required to initialize an instance of the
-    class in which the trait is used.
--   [Destructor](14-classes.md#destructors) – the actions to be performed when an instance of the
-    class in which the trait is used is no longer needed.
-
-If a member has no explicit visibility, `public` is assumed.
-
-**Examples**
-
-```PHP
-trait T
-{
-  private $prop1 = 1000;
-  protected static $prop2;
-  var $prop3;
-  public function compute( ... ) { ... }
-  public static function getData( ... ) { ... }
-}
-```
-