Re: Grafts, Traits, horizontal reuse

From: Date: Fri, 17 Apr 2009 14:16:05 +0000
Subject: Re: Grafts, Traits, horizontal reuse
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-43725@lists.php.net to get a copy of this message
Hi Tom, On 15 Apr 2009, at 16:13, Tom Boutell wrote:
PHP needs "real" horizontal reuse, no question. Looking forward to get this discussion running once again after 5.3 is released :)
My first reaction to traits was positive - it's simple and simple is good. However I'm very concerned about the implications of not allowing state. In the real world people are going to want to do horizontal reuse that involves state. So they will work around it.
I share you're concerns about state. Even though, I would like to keep Traits as simple as possible. From my perspective, it would be possible to introduce a full-grained language concept for traits like proposed in the literature [1]. But, it is quite complex. On the other hand, this language constructs would be only used rarely, and in this rare situations, it would be probably beneficial to have them at hand. Merging attributes/properties of traits, aliasing and so on. For the sake of simplicity, we might discuss a very basic solution. It would be possible to introduce trait-local state only. Thus, all properties defined in a trait are only available within methods of the same trait, no other operations are able to access these properties. How ever, there are also corner cases. (Behavior might be different in case of name clashes for dynamically created properties within a composition, changing behavior depending on the order of method invocations on a single object)
My feeling is that traits should permit state and allow the renaming of member variables just as they allow the renaming of methods. Just to be clear, there is no such thing like renaming. Renaming is just not possible with a dynamic language like PHP. ($this->$bar = 'baz'; $this->$foo();... )
Best regards Stefan [1] http://www.iam.unibe.ch/~scg/Archive/Papers/Berg07eStatefulTraits.pdf -- Stefan Marr Programming Technology Lab Vrije Universiteit Brussel Pleinlaan 2 / B-1050 Brussels / Belgium http://prog.vub.ac.be/~smarr

« previous php.internals (#43725) next »