Traits expecting interfaces implicitly leads to expensive runtime checks
| From: | Nathan Nobbe | Date: | Thu, 09 Dec 2010 07:44:47 +0000 |
| Subject: | Traits expecting interfaces implicitly leads to expensive runtime checks | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-50919@lists.php.net to get a copy of this message | ||
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.
<?php
trait InnerIteratorImpl {
public function apply() {
if(!$this instanceof Iterator)
throw new UnexpectedValueException(get_class($this) . ' not an
Iterator ..');
...
}
}
?>
do you not think checks like this will be common / messy / performance
costly; is there something i'm missing?
thx,
-nathan