Creates a predicate Closure that is true when the passed class or object is an instance of the bound class.
/**
* @param object|class-string $class
* @return Closure(object|class-string):bool
*/
Objects\isInstanceOf($class): ClosureWhen Objects\isInstanceOf() is called, it returns the following Closure which can be used like a regular function.
/**
* @param object|class-string $target
* @return bool
*/
$function ($target): boolThis can be used to create a simple closure which can be used as a regular function.
$isException = Objects\isInstanceOf(\Exception::class);
var_dump($isException(new \RuntimeException())); // true
var_dump($isException(new \stdClass())); // false
// As a filter predicate over a mixed list.
$exceptions = array_filter(
[new \RuntimeException(), new \stdClass(), new \LogicException()],
$isException
);
count($exceptions); // 2This can be called inline using currying.
var_dump(Objects\isInstanceOf(\Countable::class)(new \ArrayObject())); // true