0

How to solve this problem with call_user_func

When I call the function I have this error generated by php. Below the error.

Warning: call_user_func() expects parameter 1 to be a valid callback, function 'getChildsInMenuCount' not found or invalid function name i 

the line inside my files with the function

 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); } 

The result of var_dump(__FUNCTION__); is string(20)"getChildsInMenuCount"

 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; } } 
1
  • 1
    Why are you using call_user_func() for this? Commented Jun 27, 2017 at 17:37

2 Answers 2

3

Since it's a class method, you need to use __METHOD__, not __FUNCTION__. This will include the class prefix.

$categories_count += call_user_func(__METHOD__, $Qcategories->valueInt('id')); 
Sign up to request clarification or add additional context in comments.

Comments

0

change call_user_func parameters like below:

call_user_func(__CLASS__ . '::' . __FUNCTION__, $Qcategories->valueInt('id')); 

You must also specify the class in first parameter of call_user_func

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.