Req #53138 [NEW]: __instanceof magic method

From: Date: Fri, 22 Oct 2010 11:00:24 +0000
Subject: Req #53138 [NEW]: __instanceof magic method
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-155447@lists.php.net to get a copy of this message
From:             
Operating system: N/A
PHP version:      5.3.3
Package:          *General Issues
Bug Type:         Feature/Change Request
Bug description:__instanceof magic method

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 bug report at http://bugs.php.net/bug.php?id=53138&edit=1
-- 
Try a snapshot (PHP 5.2):            http://bugs.php.net/fix.php?id=53138&r=trysnapshot52
Try a snapshot (PHP 5.3):            http://bugs.php.net/fix.php?id=53138&r=trysnapshot53
Try a snapshot (trunk):              http://bugs.php.net/fix.php?id=53138&r=trysnapshottrunk
Fixed in SVN:                        http://bugs.php.net/fix.php?id=53138&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53138&r=needdocs
Fixed in release:                    http://bugs.php.net/fix.php?id=53138&r=alreadyfixed
Need backtrace:                      http://bugs.php.net/fix.php?id=53138&r=needtrace
Need Reproduce Script:               http://bugs.php.net/fix.php?id=53138&r=needscript
Try newer version:                   http://bugs.php.net/fix.php?id=53138&r=oldversion
Not developer issue:                 http://bugs.php.net/fix.php?id=53138&r=support
Expected behavior:                   http://bugs.php.net/fix.php?id=53138&r=notwrong
Not enough info:                     http://bugs.php.net/fix.php?id=53138&r=notenoughinfo
Submitted twice:                     http://bugs.php.net/fix.php?id=53138&r=submittedtwice
register_globals:                    http://bugs.php.net/fix.php?id=53138&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=53138&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=53138&r=dst
IIS Stability:                       http://bugs.php.net/fix.php?id=53138&r=isapi
Install GNU Sed:                     http://bugs.php.net/fix.php?id=53138&r=gnused
Floating point limitations:          http://bugs.php.net/fix.php?id=53138&r=float
No Zend Extensions:                  http://bugs.php.net/fix.php?id=53138&r=nozend
MySQL Configuration Error:           http://bugs.php.net/fix.php?id=53138&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#155447) next »