On 25.03.2010, at 22:59, Stefan Marr wrote:

> 
> On 25 Mar 2010, at 21:30, Stefan Marr wrote:
>> On 25 Mar 2010, at 16:37, Lukas Kahwe Smith wrote:
>>> Hi,
>>> 
>>> this was just brought up on IRC. my understanding is that traits have no 
>>> concept of properties, but grafts do (all hidden internally). correct?
>> Right, the Traits proposal as it is at the moment, avoids the explicit 
>> discussion of state.
>> This is not a restriction per se, but could limit the composability of 
>> traits.
>> 
>> To ensure composibility, you would have to resort to abstract methods which 
>> are implemented by the composing class.
> Maybe I should clarify that.
> 
> Currently the semantics is implicitly the following:
> 
> class Base{
> var $a;
> }
> 
> trait T1 {
> var $a;
> var $b;
> }
> 
> trait T2 {
> var $a;
> var $c;
> }
> 
> class Composite extends Base {
> use T1, T2;
> }
> 
> and Composite would have the instance variables $a, $b, $c.
> The problem would be of course that Base, T1, and T2 could use $a for 
> completely different things.
> 
> Simple, but at the cost of composability/safety.
> But for most practical cases that should be 'good enough'. As already 
> mentioned, if you want stronger guarantees, state accessor methods can be 
> used.
> 
> However, I think this implication is not discussed in the RFC, and works just 
> because PHP can create the fields dynamically. Thus, I used 'var' here in the 
> example, instead of defining a semantics and handling for public, private, 
> protected.


Right, but the issue doesnt go away if I would define a private property in the 
trait. Its still just "stupid" copy paste and so its the job of the trait user 
to ensure that there is no overlap. As such updating the trait code can easily 
break your code, its not encapsulated automatically, contrary to grafts. All in 
all I do see appeal for traits, but I think grafts just offer less wtf!?! 
surprises when code around you changes and so I favor grafts and I do not think 
we need both approaches.

So without having tested the patch, I am currently +1 on the grafts proposal as 
its in the wiki.

regards,
Lukas Kahwe Smith
m...@pooteeweet.org




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to