resolveCallable.php
Table of Contents
Functions
- resolveCallable() : callable|null
- Resolves a string callable into an actual callable.
Functions
resolveCallable()
Resolves a string callable into an actual callable.
resolveCallable(string|array<string|int, mixed>|object|null $callable) : callable|null
This function attempts to convert various callable representations into actual PHP callables that can be invoked directly. It validates the existence of functions and methods before returning them, ensuring the returned callable is executable.
Supports multiple callable formats:
- Fully qualified function names:
'oihana\core\normalize' - Static method notation:
'MyClass::method'or'MyNamespace\MyClass::method' - Array callables:
[$object, 'method']or['ClassName', 'method'] - Invokable objects: Objects implementing
__invokemethod - Closure instances and callable objects
Returns null if the callable cannot be resolved (function/method does not exist or format is invalid).
Parameters
- $callable : string|array<string|int, mixed>|object|null
-
The callable candidate to resolve. Can be:
- A string containing a function or method name
- An array with object/class and method name
- An object instance with __invoke method
- A Closure instance
- null
Tags
Return values
callable|null —The resolved callable that can be executed, or null if the callable cannot be resolved or does not exist in the current runtime.