rfc:traits
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
rfc:traits [2008/03/06 21:15] – created gron | rfc:traits [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Request for Comments: Traits for PHP ====== | + | ====== Request for Comments: Traits for PHP (Superseded by Horizontal Reuse for PHP) ====== |
* Version: 1.5 | * Version: 1.5 | ||
+ | * Date: 2008-03-06 | ||
+ | * Author: Stefan Marr < | ||
+ | * Status: **Superseded by [[rfc: | ||
+ | * Patch: http:// | ||
* First Published at: http:// | * First Published at: http:// | ||
* reST TXT: http:// | * reST TXT: http:// | ||
- | * Author: Stefan Marr < | ||
This RFC will discuss at first the motivation for Traits describing the rationals | This RFC will discuss at first the motivation for Traits describing the rationals | ||
Line 11: | Line 15: | ||
additional resources about Traits are given. | additional resources about Traits are given. | ||
+ | **This RFC is outdated and replaced by [[rfc: | ||
===== Introduction ===== | ===== Introduction ===== | ||
Line 104: | Line 109: | ||
The next sections will discuss on more advanced techniques and describe how the | The next sections will discuss on more advanced techniques and describe how the | ||
current implementation of Traits for PHP works. | current implementation of Traits for PHP works. | ||
+ | |||
==== The Flattening Property ==== | ==== The Flattening Property ==== | ||
Line 259: | Line 265: | ||
class Talker { | class Talker { | ||
use A, B { | use A, B { | ||
- | | + | |
- | | + | |
} | } | ||
} | } | ||
Line 275: | Line 281: | ||
class Talker { | class Talker { | ||
use A, B { | use A, B { | ||
- | | + | |
- | | + | |
- | | + | |
} | } | ||
} | } | ||
Line 290: | Line 296: | ||
class will consist of following three methods: | class will consist of following three methods: | ||
- | * '' | + | |
- | * '' | + | * '' |
- | * '' | + | * '' |
Since the alias operation adds a new name to an existing method body, the | Since the alias operation adds a new name to an existing method body, the | ||
Line 498: | Line 504: | ||
This section collects proposals for alternative Traits syntaxes. | This section collects proposals for alternative Traits syntaxes. | ||
+ | |||
+ | ==== Scala Synthax and practical example ==== | ||
+ | |||
+ | This is inpired from [[http:// | ||
+ | |||
+ | <code php> | ||
+ | trait User_Comments | ||
+ | { | ||
+ | | ||
+ | { | ||
+ | $db = App:: | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | |||
+ | | ||
+ | { | ||
+ | $db = App:: | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class App_Email with User_Comments {} | ||
+ | |||
+ | class App_Document with User_Comments | ||
+ | |||
+ | | ||
+ | { | ||
+ | $db = App:: | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | } | ||
+ | // PHP notice : ' | ||
+ | |||
+ | $doc = new App_Document; | ||
+ | |||
+ | echo is_a($doc, ' | ||
+ | echo is_a($doc, ' | ||
+ | echo is_with($doc, | ||
+ | </ | ||
+ | |||
+ | We deal with conflicting class definitions by simply ignoring them. | ||
+ | |||
+ | <code php> | ||
+ | trait Conflict_Comments | ||
+ | { | ||
+ | | ||
+ | { | ||
+ | | ||
+ | } | ||
+ | } | ||
+ | |||
+ | class App_Document_Conflict with User_Comments, | ||
+ | |||
+ | | ||
+ | { | ||
+ | $db = App:: | ||
+ | | ||
+ | |||
+ | | ||
+ | } | ||
+ | } | ||
+ | // PHP notice : ' | ||
+ | // PHP notice : ' | ||
+ | |||
+ | $doc = new App_Document_Conflict; | ||
+ | |||
+ | echo is_a($doc, ' | ||
+ | echo is_with($doc, | ||
+ | echo is_with($doc, | ||
+ | </ | ||
=== Alternative Keywords for use === | === Alternative Keywords for use === | ||
Line 680: | Line 763: | ||
Last but not least, in this Phd thesis http:// | Last but not least, in this Phd thesis http:// | ||
two case studies have been publish illustrating the benefits Traits are providing. | two case studies have been publish illustrating the benefits Traits are providing. | ||
+ | |||
===== Changelog ===== | ===== Changelog ===== | ||
- | gron 2008-03-05 14:15:45 | + | gron 2008-03-05 14:15:45\\ |
- added new style of traits composition and replaced the notion of an explicit exclude operator in favor for a very explicit conflict resolution | - added new style of traits composition and replaced the notion of an explicit exclude operator in favor for a very explicit conflict resolution | ||
- | gron 2008-02-25 16:08:35 | + | gron 2008-02-25 16:08:35\\ |
- fixed version number and some typos | - fixed version number and some typos | ||
- | gron 2008-02-23 18:57:21 | + | gron 2008-02-23 18:57:21\\ |
- | - added an example to the aliasing vs renaming part illustrating the effect on recursion | + | - added an example to the aliasing vs renaming part illustrating the effect on recursion\\ |
- added a syntax proposal which expresses the opposing character of aliasing(add) and excluding(remove) very well | - added a syntax proposal which expresses the opposing character of aliasing(add) and excluding(remove) very well | ||
- | gron 2008-02-21 23:02:01 | + | gron 2008-02-21 23:02:01\\ |
- | - added several new notation proposals | + | - added several new notation proposals\\ |
- added link to patch for PHP_5_3 | - added link to patch for PHP_5_3 | ||
- | gron 2008-02-20 18:47:17 | + | gron 2008-02-20 18:47:17\\ |
- | - introduced explicit description of abstract methods to be used as requirements specification for traits (useful to access state) | + | - introduced explicit description of abstract methods to be used as requirements specification for traits (useful to access state)\\ |
- | - moved part about interface propagation to the section of rejected features | + | - moved part about interface propagation to the section of rejected features\\ |
- | - added a section about common misconceptions i.e. aliasing is not renaming | + | - added a section about common misconceptions i.e. aliasing is not renaming\\ |
- added various syntax proposals | - added various syntax proposals |
rfc/traits.1204838144.txt.gz · Last modified: 2017/09/22 13:28 (external edit)