On 27/02/2008, Stefan Marr <[EMAIL PROTECTED]> wrote:
> Hi Richard,
>
>  Richard Quadling schrieb:
>
> > Traits as namespaces would solve the issue of conflict in the class
>  > Talker (you would have to explicitly say which trait the method came
>  > from.
>
> Yes, this would solve the conflicts, but is this really handy?
>  Every explicit reference to a trait/class name has to be adjusted if the
>  name changes or if there are any incompatible changes in the hierarchies.
>  Explicit references by names is probably always a solution, but not the
>  best. The inventors of the trait idea tried to avoid it in favor to
>  avoid the fragility introduced by it.
>
>
>
>  >
>  > I don't know if this can all be resolved at compile time. Surely the
>  > use of call_user_func() and others would impact somehow.
>  >
>  > If trait C requires trait D, then this may lead to longer namespaces -
>  > but from my understanding the purpose of namespaces is to resolve
>  > collisions, so it cannot be avoided when there are collisions. (Though
>  > my example doesn't collide - but that's not the point).
>  >
>  > I hope this makes some sense.
>
> It would be a possible way, but personally I would not like to go there.

I can certainly understand your reluctance. It does make things look
complicated.

But my first reasoning for suggesting it is that we are have
namespaces in PHP6 primarily to reduce the conflicts between built in
classes and userland classes/libraries.

By having an alternative aliasing mechanism for traits, we now have 2
mechanisms to learn, both of which resolve names in some way. (For:
traits aren't namespaces, Against: Trait conflict resolution certainly
looks like it could be solved with namespaces).

Your primary argument against them of "has to be adjusted if the name
changes" holds true with namespaces any way. In fact if
method/class/interface/function X becomes
method/class/interface/function Y, I have to change something anyway.

So, this is the norm, not the exception.



My second reasoning is that namespaces act as encapulation. They are
still white-box. But encapsulated. So inside the trait all the methods
can talk to each other quite happily (statically or otherwise).


It just works and is based upon existing ideas (assuming we are in a PHP6).







-- 
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"

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

Reply via email to