Callback
in package
Class Callback
A comprehensive utility class for inspecting and analyzing PHP callables.
This class provides detailed introspection capabilities for various types of callables including functions, methods (static and instance), closures, and invokable objects. It leverages PHP's reflection capabilities to extract metadata about parameters, file locations, and callable types.
Tags
Table of Contents
Methods
- info() : array{type: string, label: string, required: int, total: int, name: string, filename: string|false}
- Analyzes a callable and returns comprehensive information about it.
Methods
info()
Analyzes a callable and returns comprehensive information about it.
public
static info(callable $callback) : array{type: string, label: string, required: int, total: int, name: string, filename: string|false}
This method inspects various types of PHP callables and extracts detailed metadata including parameter counts, callable type, source location, and a human-readable label. It handles all standard PHP callable formats:
- String function names: 'strlen', 'array_map'
- Array method calls: [$object, 'method'], ['Class', 'staticMethod']
- Closure objects: function() { ... }
- Invokable objects: objects implementing __invoke()
The method is fault-tolerant and will return error information for invalid callables rather than throwing exceptions.
Parameters
- $callback : callable
-
The callable to analyze. Can be a function name, array containing [object/class, method], closure, or invokable object.
Tags
Return values
array{type: string, label: string, required: int, total: int, name: string, filename: string|false} —Associative array containing:
- 'type': Type of callable ('function', 'method', 'closure', 'invokable', 'unknown', 'invalid')
- 'label': Human-readable description of the callable
- 'required': Number of required parameters (non-optional)
- 'total': Total number of parameters including optional ones
- 'name': Internal name of the function/method
- 'filename': Path to file where callable is defined, or false if internal