I can do $func = ['object', 'staticMethodName'];
$func = [$instance, 'publicMethodName'];
$func = 'functionName';
$func = '\namespaced\functionName';
$func = function(){ ... };
$func = $callableObject; // ( http://php.net/manual/en/language.oop5.overloading.php#objec... )
I can execute any of the above by calling `$func('doIt');`
Moreover all of those will all pass a `callable` typehint on a method call as well as the is_callable if they exist and are callable. Its quite powerful.
Though who am I kidding, PHP is also confused between numbers and arrays and strings, so I guess at least it's consistent that the language is thoroughly crazy.
Very little about PHP's treatment of functions is easy or clean.
function foo() { echo "Hello world"; }
$w = 'foo';
echo $w; // foo
$w(); // Hello world
'foo'(); // PHP Parse error: syntax error, unexpected '('
function bar() { return 'foo'; }
$x = bar();
echo $x; // foo
$x(); // Hello world
bar()(); // PHP Parse error: syntax error, unexpected '('
$o = new stdClass;
$o->baz = 'foo';
$y = $o->baz;
echo $y; // foo
$y(); // Hello world
$o->baz(); // PHP Fatal error: Call to undefined method stdClass::baz()
Heck, PHP doesn't even recognise function-call syntax applied to a function! $z = function() {
echo "Hello world";
};
$z(); // Hello world
(function() {
echo "Hello world";
})(); // PHP Parse error: syntax error, unexpected '('