この例を見てください:
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フレームワークを自分で作成しているという理由だけで、おそらくあなたが何を必要としているかを知っています...