看看这个例子:
class A
{
public function makeMethod()
{
$this->b = new B();
//create a method for class B such as a __call() method
//to catch an error trying to access a non existant class B method
$this->b->doit();
}
}
class B
{
public function __call($name,$args)
{
echo "function called: $name with arguments: $args";
}
}
$a = new A();
$a->makeMethod();
?>
这将输出:
function called: doit with arguments: Array
所以,在某种程度上,我们调用了一个不存在的函数,class B
我们仍然可以用它做点什么......例如,在你的__call
方法中,你class B
不能将执行指向某个回调函数(甚至是class A
)吗?为什么要“创造”它?(不要从开发人员的角度思考,除非你绝对必须...... :-))
只是一个想法...
Minima Framework中的页面/模块执行处理一瞥 :
public function __call($name, $arguments=NULL)
{
$function_name = "_".$name;
$trace = debug_backtrace();
$moduleCall = false;
if (isset($trace[2]))
{
if (isset($trace[2]['object']))
{
$trace = $trace[2]['object'];
if (is_subclass_of($trace, 'mmModule'))
$moduleCall = true;
}
}
$args = $this->matchArguments($name, $arguments);
if ($moduleCall) { $this->redirect ($name, $arguments); }
else
{
$this->Result = call_user_func_array(array($this, $function_name), $args);
$this->loadTemplate($name);
}
}
PS仅仅是因为我自己已经创建了一个 100% PHP 框架,也许我知道你可能需要什么......