Edit report at http://bugs.php.net/bug.php?id=53138&edit=1
ID: 53138 Updated by: cataphr...@php.net Reported by: tom at r dot je Summary: __instanceof magic method -Status: Open +Status: Bogus Type: Feature/Change Request Package: *General Issues Operating System: N/A PHP Version: 5.3.3 Block user comment: N New Comment: Make A an interface and have AWrapper implement or extend A. Overloading the instanceof operator is not an acceptable solution. Previous Comments: ------------------------------------------------------------------------ [2010-10-22 13:00:23] tom at r dot je Description: ------------ as it stands, it's possible to create a wrapper e.g. <?php class A { } class AWrapper { protected $a; public function __construct(A $a) { $this->a = $a; } public function __set($name, $value) { $this->a->$name = $value; } public function __get($name) { return $this->a->$name; } public function __call($func, $args) { return call_user_func_array(array($this->a, $func), $args); } } ?> AWrapper, now mimics the interface of A. It will work as a substitute for A, anywhere A is required. The problem is, type checking. Anywhere class "A" is used, it may be type hinted or checked using instanceof e.g. function setA(A $a) { } or $foo isntanceof 'A'; If an __instanceof magic method existed, it would be possible to get around this and have true wrapper classes. For example: public function __instanceof() { return 'A'; } Or perhaps it should return an array to allow it to wrap multiple classes. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=53138&edit=1