A little summary encountered when moving bricks on the callback function (callback function) of.
- General function
$this->callSomeFunction('some_global_php_function');
- Object instance
// Only from inside the same class
$this->callSomeFunction([$this, 'myCallback']);
// From either inside or outside the same class
$myObject->callSomeFunction([new MyClass(), 'myCallback']);
Note: The callback function available to other objects do not forget access control (public).
- Static class methods
// Only from inside the same class
$this->callSomeFunction([__CLASS__, 'myStaticCallback']);
// From either inside or outside the same class
$myObject->callSomeFunction(['\Namespace\MyClass', 'myStaticCallback']);
$myObject->callSomeFunction(['\Namespace\MyClass::myStaticCallback']); // PHP 5.2.3+
$myObject->callSomeFunction([MyClass::class, 'myStaticCallback']); // PHP 5.5.0+
- Anonymous function
$this->callSomeFunction(function() {
// do something in anonymous function
});