私は使用方法を知っています:
call_user_func_array(array($className, $methodName), array($_POST)) ;
クラスで関数を呼び出してパラメーターを送信するには。
しかし、クラスだけを呼び出して、__コンストラクターに入るパラメーターを渡すにはどうすればよいでしょうか?
手動で行うには、次のようにします。
$myTable = new Supertable(array('columnA', 'columnB'), 5, 'Some string') ;
どちらがうまくいくでしょう。call_user_func_array と同様の機能を実現するには、どのような関数が必要ですか?
ここに、私がやっていることの完全なコンテキストがあります:
function __autoload($classname) {
@include $classname.'.php' ;
}
$className = 'supertable' ;
$methodName = 'main' ;
if(class_exists($className, true)) {
if(method_exists($className, $methodName)) {
$reflection = new ReflectionMethod($className, $methodName) ;
if($reflection->isPublic()){
call_user_func_array(array($className, $methodName), array($_POST)) ;
} elseif($reflection->isPrivate()) {
echo '<span class="state">Private</span> method <span class="methodname">'.$methodName.'</span> can not be accessed directly.' ;
} elseif($reflection->isProtected()) {
echo '<span class="state">Protected</span> method <span class="methodname">'.$methodName.'</span> can not be accessed directly.' ;
}
} else {
echo 'The method <span class="methodname">'.$methodName.'</span> does not exist.' ;
}
} else {
echo 'The class <span class="classname">'.$className.'</span> does not exist.' ;
}