我在程序中使用了以下代码。php call_user_func_array()警告
class A {
function __call($fname,$arguments)
{
$methods = array('get', 'set');
foreach ($methods as $method) {
if(strstr($fname,$method))
{
$fname = str_replace($method, "", $fname);
$function = $method."method";
if($method == "set")
{
call_user_func_array("setmethod", array($fname,$arguments[0]));
}
if($method == "get")
{
call_user_func_array("getmethod", $fname);
}
break;
}
}
}
function setmethod ($key,$value)
{
$this->$key = $value;
}
function getmethod($key)
{
return $this->$key;
}
}
和我越来越warrning这样
“警告:call_user_func_array()预计参数1是一个有效的回调,功能‘使用setMethod’未找到或无效的函数名”
和程序停止,没有进一步显示。
所以,我把它这是一个类的一部分? – vollie
'call_user_func_array'不会奇迹般地识别出您处于类上下文中。使用'array($ this,“setmethod”)'而不是''setmethod“'。 – Yoshi