PHPでAPIを書いています。私は魔法の機能を実装する基本クラスを持っています__call
:
class Controller
{
public function __call($name, $arguments)
{
if(!method_exists($this,$name))
return false;
else if(!$arguments)
return call_user_func(array($this,$name));
else
return call_user_func_array(array($this,$name),$array);
}
}
そして、このような子クラス:
class Child extends Controller
{
private function Test()
{
echo 'test called';
}
}
だから私はこれを行うとき:
$child = new Child();
$child->Test();
ページをロードすると時間がかかり、しばらくすると、Web ブラウザーはページを要求できないことを出力します。PHP からの出力はなく、Web ブラウザのエラーのみです。
Apache エラー ログ (最後の部分のみ):
...
[Tue Sep 24 12:33:14.276867 2013] [mpm_winnt:notice] [pid 1600:tid 452] AH00418: Parent: Created child process 3928
[Tue Sep 24 12:33:15.198920 2013] [ssl:warn] [pid 3928:tid 464] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Tue Sep 24 12:33:15.287925 2013] [mpm_winnt:notice] [pid 3928:tid 464] AH00354: Child: Starting 150 worker threads.
[Tue Sep 24 12:38:43.366426 2013] [mpm_winnt:notice] [pid 1600:tid 452] AH00428: Parent: child process exited with status 3221225725 -- Restarting.
[Tue Sep 24 12:38:43.522426 2013] [ssl:warn] [pid 1600:tid 452] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
私は間違いを見つけることができませんが、関数 Test が保護されていれば、すべて正常に動作します。
見つかった解決策:
public function __call($name, $arguments)
{
if(!method_exists($this,$name))
return false;
$meth = new ReflectionMethod($this,$name);
$meth->setAccessible(true);
if(!$arguments)
return $meth->invoke($this);
else
return $meth->invokeArgs($this,$arguments);
}