Re: __call overload detection
| From: | Mike Naberezny | Date: | Tue, 03 Jan 2006 23:54:21 +0000 |
| Subject: | Re: __call overload detection | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-21380@lists.php.net to get a copy of this message | ||
Marcus Boerger wrote:
If you need more it is up to you to provide the infrastructure. Remember we will not in anyway allow __call to handle inheritance.Hi Marcus, If one is determined enough, at least visibility can be faked by exception trace introspection. Below demonstrates protected, replace __CLASS__ with get_class($this) for private. I see very little or no real world application for this and the procedure is quite expensive. <?php class Test {
public function __construct() {
// demo, should echo "hello"
echo $this->nonexistant;
}
public function __get($offset) {
try {
throw new Exception();
} catch (Exception $e) {
$trace = $e->getTrace();
$caller = isset($trace[2]['class']) ? $trace[2]['class'] : null;
if ($caller === null
|| $caller != __CLASS__
&& !is_subclass_of($caller, __CLASS__)) {
throw new Exception('Access to protected ' .__CLASS__. '::' .$offset. ' from context '. $caller);
}
}
return 'hello';
}
}
$t = new Test(); // hello echo $t->nonexistant; // exception?> Mike