Skip to content
Advertisement

PHP check if function callable but not invokable object?

I want a custom is_callable_func function which captures correctly functions and closures but disregards custom objects which implement the __invoke method.

Example:

JavaScript

I tried using:

JavaScript

but it doesnt work, since, for example, anonymous functions are objects. Possible??

PS: would appreciate if proposed solution is backwards-compatible to php 5.3

Advertisement

Answer

You can check what type of object the callable is, a closure will be an instance of Closure

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement