Primordyx Framework Documentation

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
since
1.0.0

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
example
// Analyzing a built-in function
$info = Callback::info('strlen');
// Returns: ['type' => 'function', 'label' => 'strlen', 'required' => 1, 'total' => 1, ...]

// Analyzing a method call
$info = Callback::info([$myObject, 'doSomething']);
// Returns: ['type' => 'method', 'label' => 'MyClass->doSomething', ...]

// Analyzing a static method
$info = Callback::info(['MyClass', 'staticMethod']);
// Returns: ['type' => 'method', 'label' => 'MyClass::staticMethod', ...]

// Analyzing a closure
$closure = function($a, $b = 'default') { return $a . $b; };
$info = Callback::info($closure);
// Returns: ['type' => 'closure', 'label' => 'Closure@line 15', 'required' => 1, 'total' => 2, ...]
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

        
On this page

Search results