3 ms·
I feel like its callable system is simple, easy to use, and frankly awesome. I can do $func = ['object', 'staticMethodName']; $func = [$instance, 'publicMeth
by donatj 12y ago
I feel like its callable system is simple, easy to use, and frankly awesome.
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#object.call 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.
- jules 12y agoThe problem is that a function is a thing. A string is a different thing. Imagine if arrays were represented as comma delimited strings, and you had a function isArray to check if a string has the right format to represent an array. That would be ridiculous right? An array should be its own type. The same goes for functions. Representing functions as string names is just as crazy as representing arrays as comma delimited strings. 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.
- skybrian 12y agoRidiculous or not, Tcl works like this. Everything is a string.