To quote PHP:
Anonymous functions are currently implemented using the Closure class. This is an implementation detail and should not be relied upon.
Now, that said, the following checks are deemed unreliable:
function myFunction(Closure $callback){}
if(!($callback instanceof Closure)){}
Which brings us to using is_callable(). This is fine, however if one requires a true "closure", (as an argument, or what-such) then is_callable() isn't strict enough. The following of course dumps bool(true) for each:
function myFunction(){}
class MyClass{
public function __invoke(){}
}
var_dump(is_callable('myFunction'));
var_dump(is_callable(new MyClass));
How, without relying on the Closure class (given is is in fact unreliable) can one strictly identify a "closure"?
Update
It has occurred to me I was falling in the direction of bad design. However, despite this question being answered, I think it would be appreciated if anyone could suggest answers to the posed question, if not purely for the academic element of it.
Update (again)
Since the release of PHP 5.4 (awhile ago now) the Closure type is no longer an "implementation detail", and can be relied on. function f(Closure $g) { } is all good.
__invoke-able objects or function names by string, it will convolute the module I'm working on, and it's intended purpose.__invoke-able object or string function name.interface, e.g.interface Action { public function exec($arg);})? Thats much more OOPish. I cannot imagine one single purpose, why it should make sense to restrict callables to a single kind... I don't know, what you are trying to achieve, but maybe there will be situations, where a single closure gets much too complex and packing its functionality into a callable class makes the code much cleaner.