Date: 07/04/06 (PHP Development) Keywords: no keywords I did a bit of research today, and came up with the following interesting method:
class MyClass {
private $sub_data; // some random object
public function doSomething() {
...
}
private function __call($name, $args) {
if( is_object($this->sub_data) ) {
return call_user_func(array(&$this->sub_data, $name), $args);
}
else {
echo "Error: sub_data is not an object. This method was not found\n";
return;
}
}
}
I have a class defined with a property ($this->sub_data) that holds a variable class instance. What the $__call() method allows me to do is to proxy method calls invoked on my "container" class down to the $this->sub_data class without having to know anything about the sub_data object instance. More info: Overloading call_user_func
|