Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP call_user_func with class and arguments

Tags:

php

callback

I need to use call_user_func . I will need to call a function in a separate file in separate class with 5 arguments . I couldnt find any example here http://php.net/manual/en/function.call-user-func.php . IS there any way to do this ?

like image 753
Pit Digger Avatar asked Aug 02 '12 15:08

Pit Digger


1 Answers

Personally I use call_user_func_array.

$result = call_user_func_array(array($objectInstance, 'objectMethod'), array('parameter one', 'parameter two'));

If the method is a static one, replace $objectInstance with the name of the class being used. You can also use stand-alone functions too:

$result = call_user_func_array('functionName', array('parameter one', 'parameter two'));

Hope this makes sense? :]

However in the future, try and show us what you have and haven't done :]

like image 174
Azirius Avatar answered Oct 14 '22 22:10

Azirius