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.
Best regards
Stefan
>
> Best regards
> Stefan
>
>
>
> --
> Stefan Marr
> Software Languages Lab
> Vrije Universiteit Brussel
> Pleinlaan 2 / B-1050 Brussels / Belgium
> http://soft.vub.ac.be/~smarr
> Phone: +32 2 629 2974
> Fax: +32 2 629 3525
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
Stefan Marr
Software Languages Lab
Vrije Universiteit Brussel
Pleinlaan 2 / B-1050 Brussels / Belgium
http://soft.vub.ac.be/~smarr
Phone: +32 2 629 2974
Fax: +32 2 629 3525