如何使用call_user_func
解决此问题当我调用该函数时,我有这个由php生成的错误。低于错误。
while ($Qcategories->fetch() ) {
$categories_count++;
$rows++;
if ((!isset($_GET['cID']) && !isset($_GET['pID']) || (isset($_GET['cID']) && ((int)$_GET['cID'] === $Qcategories->valueInt('id')))) && !isset($cInfo) && (substr($action, 0, 3) != 'new')) {
$category_childs = ['childs_count' => AdministratorMenu::getChildsInMenuCount($Qcategories->valueInt('id'))];
$cInfo_array = array_merge($Qcategories->toArray(), $category_childs);
$cInfo = new objectInfo($cInfo_array);
}
我的文件中的行与函数
var_dump(__FUNCTION__);
is string(20)
class AdministratorMenu {
// Count how many subcategories exist in a category
public static function getChildsInMenuCount($id) {
$OSCOM_Db = Registry::get('Db');
$categories_count = 0;
$Qcategories = $OSCOM_Db->prepare('select id
from :table_administrator_menu
where parent_id = :parent_id
');
$Qcategories->bindInt(':parent_id', $id );
$Qcategories->execute();
while ($Qcategories->fetch() !== false) {
$categories_count++;
$categories_count += call_user_func(__FUNCTION__, $Qcategories->valueInt('id'));
}
return $categories_count;
}
}
" getChildsInMenuCount"的结果
{{1}}
答案 0 :(得分:3)
由于这是一种类方法,因此您需要使用__METHOD__
,而不是__FUNCTION__
。这将包括类前缀。
$categories_count += call_user_func(__METHOD__, $Qcategories->valueInt('id'));
答案 1 :(得分:0)
更改call_user_func
参数,如下所示:
call_user_func(__CLASS__ . '::' . __FUNCTION__, $Qcategories->valueInt('id'));
您还必须在call_user_func