rfc:traits
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
rfc:traits [2009/01/18 17:02] – Added URL to the patch gron | rfc:traits [2012/01/20 12:48] – Added to the title that it is superseded by another RFC gron | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Request for Comments: Traits for PHP ====== | + | ====== Request for Comments: Traits for PHP (Superseded by Horizontal Reuse for PHP) ====== |
This RFC is outdated and replaced by [[rfc: | This RFC is outdated and replaced by [[rfc: | ||
Line 265: | Line 265: | ||
class Talker { | class Talker { | ||
use A, B { | use A, B { | ||
- | | + | |
- | | + | |
} | } | ||
} | } | ||
Line 281: | Line 281: | ||
class Talker { | class Talker { | ||
use A, B { | use A, B { | ||
- | | + | |
- | | + | |
- | | + | |
} | } | ||
} | } | ||
Line 504: | 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 === |
rfc/traits.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1