Callback format which provides by the library is backward compatible with the standard format.
Variants of the standard format:
- string
"functionName"
- array
[$object, "methodName"]
- array
["ClassName", "staticMethodName"]
- string
"ClassName::staticMethodName"
- an object with a method
__invoke
- Closure
All of these variants are supported in the library.
Bound arguments are specified in the element with index 2 as a numeric array.
[$object, "methodName", $args]
: calls$object->methodName()
with arguments from$args
.["ClassName", "staticMethodName", $args]
["ClassName::staticMethodName", null, $args]
- similar to the previous[null, "funcName", $args]
- global function (without class)[$object, null, $args]
- call the object as function (__invoke()
)[null, $closure, $args]
Example:
$callback = [$object, 'methodName', [1, 2]];
Callback::call($callback, [3, 4]); // $object->methodName(1, 2, 3, 4)
The optional flag for bind context are specified in the element with index 3.
[$object, "methodName", $args, true]
[$object, "methodName", null, true]
- bind context without arguments- ...
$callback = [$object, 'privateMethodName', [1, 2], true];
Callback::call($callback, [3, 4]); // $object->privateMethodName(1, 2, 3, 4)
The associative array. All fields are optional.
function
- a global function name or a closure.object
- an object. Needsmethod
(or__invoke
by default)class
- a class name. Needsmethod
for static method name.method
- a method name. Needsobject
orclass
.args
- a list of arguments for binding (numeric array).bind
- a bind flag (boolean, FALSE by default).
$callback = [
'class' => 'MyClass',
'method' => 'privateStaticMethodName',
'bind' => true,
];