You can put the function name in a string:
if($var) { $func = 'shout'; }else { $func = 'whisper'; }
Later:
$obj->$func
You can also use the callback:
if($var) { $func = array($obj, 'shout'); }else { $func = array($obj, 'whisper'); }
Further:
call_user_func($func);
or
call_user_func_array($func, $args);
source share