[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-internals
Subject:    [PHP-DEV] Traits expecting interfaces implicitly leads to expensive runtime checks
From:       Nathan Nobbe <quickshiftin () gmail ! com>
Date:       2010-12-09 7:44:47
Message-ID: AANLkTim9wJSM9XrZu7JHmvX04ZfE+Bikz_-SP+6aJx79 () mail ! gmail ! com
[Download RAW message or body]


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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic