Validating a closure (double check or not)?

Suppose an object has this method
public function __construct($path, $callable)
And, I want the $callable a closure or invokable object.

Should I just validate it like this : if(!method_exists($callable, '__invoke') ?
Or using double check : if (!is_object($callable) || !method_exists($callable, '__invoke')) ?

In my thought, one has a method so it must be an object (no need to check whether it’s object or not)
But, sometimes I see developers use the second approach.
P.S. I know that I can use type hinting, but I want my app support PHP 5.3

What about is_callable?

I just want closure or invokable object, not pure function

closures are of the Closure class.

So, should I just if($callable instanceOf Closure)
Or if(is_object($callable) && $callable instanceOf Closure) ??

the instanceof test works with any variable.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.