I have the following code; what should be added to the decorator class to pass the check of method_exists()? In real task I can’t change the function that calls method_exists().
Also any idea how to cheat ‘get_class_methods()’ and ‘get_class_vars()’?
class real {
function __construct($arg1,$arg2)
{
}
function test()
{
echo "test output\n";
}
}
class decorator
{
protected $real;
function __construct()
{
eval('$this->real=new real('.implode(',',func_get_args()).');');
}
function __call($method,$args)
{
echo "called $method\n";
$ret=call_user_func_array(array($this->real, $method), $args);
return $ret;
}
public function __isset($name)
{
echo "isset $name\n";
}
}
//-----Can't change below
$r=new decorator(1,2);
if (!method_exists($r,'test')) {die ("method 'test' does not exist, Fail :(\n");}
echo $r->test();
Any ideas ? (I’m thinking of generating a wrapper class by eval())
This answer is extremely simple:
Make the decorator class extend the real class
This is a much better design, and it works!
To better solve the underlying problem of inspecting a proprietary encoded program, I also suggest the use of XDebug’s execution_trace.