Lars Strojny schreef:
Hi Jochem,

Am Mittwoch, den 20.02.2008, 00:06 +0100 schrieb Jochem Maas:
[...]
if a trait would could contain all the methods required to implement
an interface and a class uses it (the trait) and implements the
relevant interface would it (the interface) be satified?

Yes. The following should work:
interface IFoo {
   public function method();
}

trait TFoo {
   public functin method() {
      echo "Hello World!";
   }
}

class CFoo implements IFoo
{
   use TFoo;
}

This would be fine.

also might it be an idea to allow a trait to specify that it
implements an interface for the purposes of development (errors
triggered due to incorrect/incomplete implementation)
BUT not have the interface be carried to any classes that use the
trait?

I don't see any sence in it. Why should one generalize an interface of a
trait?

I don't suppose you would, I thinking more along the lines of having it
a developer tool - using implements on a trait would force the developer to
put in the correct methods, it might help a team that had say 1 interface, 2 
traits
(which both contain a set of methods that satify said interface) and a large 
number
of classes that implement one or other of the traits ... having the trait state
that it's capable of handling an implementation might save some WTF because
compile time errors would happen on the trait if it broke the interface 
signature,
rather than on the class ... an interface related error on the class it might 
not be
obvious to the developer with regard to the fact that the/a trait the class is 
using
was for the purpose of satifying an interface the class states it is 
implementing.

I'm thinking that it will proably occur quite often that a fairly simple 
interface
will be 'covered' by a trait and that said trait would be used solely for 
satifying
said interface implementation and used as such for classes that wish to 
implement
said interface.

to quote Troels:

"Class inheritance (The ``extends`` keyword) inherits type
+ implementation. Interface inheritance (The ``implements`` keyword)
inherits type (but not implementation). Traits fill the missing hole
by allowing inheritance of implementation, but not type."

that sounds more than reasonable, but it might be worth offering an aid
to developers during the compile time phase, with regard to the 'link' between
a trait and an interface (assuming you would agree that it's not unlikely that
the two would be used in tandem on occasion) without imposing/implying anything
at run time (i.e. a trait may implement an interface to ensure correctness but
that has no effect on any class that uses it, classes must explicitly state it's
intention to implement an interface)

I may have said something stupid - but given the ability of your average php 
user
to stupid things with the functionality offered to him/her, my comments might
aid in thrashing out such details in order to limit a user's ability to do 
stupid
things :-)


cu, Lars

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

Reply via email to