invoke
suggest change__invoke runs when the object is called as a function. That is useful for callbacks and for small function-like objects.
class Invokable
{
/**
* This method will be called if object will be executed like a function:
*
* $invokable();
*
* Args will be passed as in regular method call.
*/
public function __invoke(...$args): void
{
print_r(func_get_args());
}
}
// Example:
$invokable = new Invokable();
$invokable(1, 2, 3);
// outputs:
# Array
# (
# [0] => 1
# [1] => 2
# [2] => 3
# )
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents