View Full Version : Class Method with call_user_func

02-23-2010, 07:18 AM
Can anyone tell me how this can be done?
I'm trying to invoke a private function in my class with another private function using the call_user_func function:


The call_user_func function should (theoretically) call the private function, but instead is throwing this error:

First argument is expected to be a valid callback

Which obciously means that this is the wrong way of doing this. Does anybody know the proper way of going about this?


Here's how you would do this:
Where classname is the name of your class.

02-23-2010, 07:55 AM
You need to pass the instance in by an array too like the following:

Here's an example where I've used it:

* DetectRequestType - Checks to see all the keys and values of the post request
* as the post can contain more than one request, look through the ones we need for
* returned data.
* $param $postReq - Reference of the $_POST superglobal to search.
public function DetectRequestType(&$postReq)
foreach($postReq as $key => $post)
# Find first and only valid request to return data on ^^
if(in_array($key, (array)$this->_postTypes))
$methodName = (string)"Get" . $key . "Data";

if(method_exists($this, $methodName))
return (string)(call_user_func(array($this, $methodName), intval($post)));