Personally, I believed that traits are a *compile time injection* to a class, so that at runtime a class behaves completely as it would if trait methods were implemented directly in the class. That said, everything like trait requirements for a certain interface, should be done at compile time and constructions like abstract foo(); in a trait serve that purpose. IMHO.
2010/12/10 Stefan Marr <[email protected]> > Hi Nathan: > > > On 09 Dec 2010, at 23:42, Nathan Nobbe wrote: > > What I'm getting at is the scenario when a trait is designed to be used > in > > concert with the class in which it is being used. In this case the trait > > expects certain functions to be available on the class in which it is > used > > with. If the methods aren't there (or checked for at runtime) a fatal > error > > is raised. > > > > A quick example > > <?php > > class A { > > use AHelper; > > > > function blah() {} > > } > > > > trait AHelper { > > function meh() { > > // hoping we get used w/ instances of A ... > > return $this->blah() * 5; > > } > > } > > > > class B { > > use AHelper; > > > > /// waiting for a runtime error if blah() is ever called .. > > } > > ?> > > > > Do you see what I mean? > No, do not really see what you are getting at. > > How is your approach using the instanceof checks (from the first mail) > different from changing AHelper to require blah() by stating this > requirement using an abstract method definition? > For the trait it is not important where that method is implemented, it just > has to be in the final composed class. > > So, why don't you want the following trait? > > trait AHelper { > abstract function blah(); > > function meh() { > // hoping we get used w/ instances of A ... > return $this->blah() * 5; > } > > } > > You want to avoid the fatal error during runtime, right? > > Do you prefer dynamic checks over compile time checks? > > 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 > > -- С уважением, Виктор
