Callable
suggest changeA callable is anything PHP can call as a callback:
- Anonymous functions
- Names of standard PHP functions (not language constructs such as
echoorisset) - Static methods, written as
'ClassName::method'or['ClassName', 'method'] - Instance methods, written as
[$object, 'method'] - Objects that define
__invoke
Example Of referencing an object as an array element:
$obj = new MyClass();
call_user_func([$obj, 'myCallbackMethod']);
Callbacks can be denoted by callable type hint as of PHP 5.4.
$callable = function () {
return 'value';
};
function call_something(callable $fn) {
call_user_func($fn);
}
call_something($callable);
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents