Re: Traits expecting interfaces implicitly leads to expensive runtime checks

From: Date: Thu, 09 Dec 2010 08:09:03 +0000
Subject: Re: Traits expecting interfaces implicitly leads to expensive runtime checks
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-50920@lists.php.net to get a copy of this message
Hi Nathan: On 09 Dec 2010, at 08:44, Nathan Nobbe wrote: > Hi, > > I think traits will lend themselves to frequent runtime checking against the > type of class in which they were used. Consider a trait designed for use > with an Iterator class; the first thing might be to check the type of $this. Why would you need such a check? You want to ensure that the class that is using your trait obeys a certain interface, right? More specifically, you need it to implement a number of methods of an interface, correct? So, why not asking for it explicitly? <?php trait InnerIteratorImpl { abstract function next(); public function apply() { do somthing with $this->next() ... } } ?> Does that what you want it to do? 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

« previous php.internals (#50920) next »