Those are callables recognized by PHP natively. They can be invoked simply: $callable(...)
.
-
Closures:
function () { ... }
-
Static method call:
['A', 'staticMethod']
or alsoFoo::staticMethod
class A { public static function staticMethod() { ... } }
-
Method call:
[new B, 'method']
class B { public function method() { ... } }
-
Invokable class:
new C
class C { public function __invoke() { ... } }
-
Function call:
'hello'
function hello() { ... }
Extended callables are a made-up thing not recognized by PHP. They can be called using Invoker and are used for example in the Silly framework.
-
Method call:
['B', 'method']
class B { public function method() { ... } }
Warning: the method must not be static, else it will be recognized as a normal PHP callable representing a static method call.
-
Invokable class:
'C'
class C { public function __invoke() { ... } }
Warning:
C
must not be a function, else it will be recognized as a normal PHP callable representing a function call.
The Invoker will instantiate the object instances using any Container. The benefits are:
- lazy creation of objects
- objects are created by containers, which means the container can inject dependencies