Let’s pretend this is happening inside of a class method (pure example):
public function runEvent($funcName, $params)
{
$funcName($this, $params);
}
//somewhere else
function myFunc($anBOject, $paramsHere, $somethingElse = NULL)
{
//do stuff
}
$SomeClassObj->runEvent('myFunc', array('dog', 'cat'));
Can I assume PHP will execute myFunc with the first parameter being $this, second being $params, and then NULL as the 3rd param (by default)?
This question is more just for understanding how PHP deals with variable functions. Im not actually having any issues in a certain project.
Thanks!
Yes.
is called exactly the same way as
The first parameter is
$this, the second$params, there’s no third.To call functions with a variable number of arguments, use
call_user_func_array.