我的类结构如何(lib.php):
trait smartMethods{
function Numbers($length,$position){
echo $length.$position."\n";
}
}
class smartBrute {
Private $config,$smlist;
use smartMethods;
function init(){
foreach($this->config as $k => $v){
$inp = "";
foreach($v as $k2 => $v2){
($inp == "" ? $inp = $v2 : $inp .= ",".$v2);
}
$this->{$k}($inp); // Here Is Problem
}
} //EO init
} //EO Class
调用类(init.php):
$options["Numbers"] = Array(2,1);
$brute = new smartBrute($options);
$这 - > {$ķ}($ INP); < - 这是我的问题函数数字需要2个参数。没有像这样的论证$ this-> {$ k}()它有效,但我无法理解如何传递这种情况参数。
答案 0 :(得分:0)
我找到了这种解决方案,
function init(){
foreach($this->config as $k => $v){
call_user_func_array(array($this,$k),$v); // call trait Method funcs
}
}
我用call_user_func_array这个函数传递参数