Honestly, I cannot find many differences between them. They basically do the same, but the only differences I can find is that call_user_func takes more than 2 ร longer than variables (calling an empty function).
Another thing is that error handlers are different from each other, if you use a nonexistent callback function, the variable function will throw a fatal error and stop the script, and call_user_func will display a warning, but continue the script.
Also, passing parameters through a function, using variable functions gives a bit more error information regarding line numbers:
function asdf($a, $b) { return(1); }
call_user_func ('asdf', 1) :
Warning: Missing argument 2 for asdf () in G: \ test.php on line 3
-
$ a = 'ASDF'; $ a ($ a, 1) :
A warning. There is no argument 2 for asdf () called in G: \ test.php on line 10 and is defined in G: \ test.php on line 3
These errors are compiled from command line interface (CLI) tests; the error display obviously depends on your configuration.
source share