PHPackages                             phpfluent/callback - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. phpfluent/callback

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

phpfluent/callback
==================

Allows you execute callbacks in a more dynamic way

1.1.0(10y ago)1159.2k↓42.9%3[1 PRs](https://github.com/PHPFluent/Callback/pulls)1MITPHPPHP &gt;=5.4.0

Since Dec 3Pushed 2y ago3 watchersCompare

[ Source](https://github.com/PHPFluent/Callback)[ Packagist](https://packagist.org/packages/phpfluent/callback)[ Docs](https://github.com/PHPFluent/Callback)[ RSS](/packages/phpfluent-callback/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (1)

PHPFluent\\Callback
===================

[](#phpfluentcallback)

[![Build Status](https://camo.githubusercontent.com/a26b37149f319aace249c52a247a45a7a3c523575086c26cc1f964c62611dec3/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f504850466c75656e742f43616c6c6261636b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](http://travis-ci.org/PHPFluent/Callback)[![Code Quality](https://camo.githubusercontent.com/eea17c4b9d2a09aa00033e65872311387a5f6cb46d440e9faf0684f6dbc5ab70/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f504850466c75656e742f43616c6c6261636b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/PHPFluent/Callback/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/a84992b71af2f257afd006b547083d62a6f9f0990fc98c525b77702201bf5e5f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f504850466c75656e742f43616c6c6261636b2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/PHPFluent/Callback/?branch=master)[![Latest Version](https://camo.githubusercontent.com/44a677db7c29239d4f8e84a621ab70ecf5ec583e14a164a5664350aace5282fa/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f706870666c75656e742f63616c6c6261636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpfluent/callback)[![Total Downloads](https://camo.githubusercontent.com/97ba8e945ccf788832015ae6963de6cf00e281fda3764c38ecb80a4620c8ee70/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f706870666c75656e742f63616c6c6261636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpfluent/callback)[![License](https://camo.githubusercontent.com/7f83c7ee3bef818a9ae53a1811a4b7b72533c5d84865c94bac1d1ae0a627504b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f706870666c75656e742f63616c6c6261636b2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/phpfluent/callback)

Allows you execute callbacks in a more dynamic way.

Installation
------------

[](#installation)

The package is available on [Packagist](https://packagist.org/packages/phpfluent/callback). You can install it using [Composer](http://getcomposer.org).

```
composer require phpfluent/callback
```

### Dependencies

[](#dependencies)

- PHP 5.4+

Usage
-----

[](#usage)

All examples within this document assume you have the following statement at the beginning of the file:

```
use PHPFluent\Callback\Callback;
```

Define your callable
--------------------

[](#define-your-callable)

### Closures

[](#closures)

```
$callback = new Callback(
    function () {
        // My callable content.
    }
);
```

### Object methods

[](#object-methods)

```
$callback = new Callback(array($object, 'methodName'));
```

### User defined functions

[](#user-defined-functions)

```
$callback = new Callback('my_function');
```

### PHP native functions

[](#php-native-functions)

```
$callback = new Callback('str_replace');
```

Executing your callable
-----------------------

[](#executing-your-callable)

There are many ways you can execute the callable.

### invoke()

[](#invoke)

```
$callback->invoke($arg1, $arg2, $arg3);
```

### invokeArguments()

[](#invokearguments)

```
$callback->invokeArguments($arrayArguments);
```

### \_\_invoke()

[](#__invoke)

```
$callback($arg1, $arg2, $arg3); // call_user_func() and call_user_func_array() will work like a charm
```

Arguments
---------

[](#arguments)

If you're reading this document you may be wondering why this library was written since everything written on it is already possible just using native PHP features.

This library provides more flexibility when defining the arguments to be used when you call your callback. That's useful when you working with callbacks in a predefined structure but you don't want all arguments.

### Names

[](#names)

`Callback` will execute your callback based on its parameters name.

```
$callable = new Callback(
    function ($foo, $bar = true) {
        // My callable body
    }
);
$callable->invokeArguments(
    array(
        'foo' => 'PHPFluent',
    )
);
```

### Types

[](#types)

Doesn't matter the order of the arguments, `Callback` will put it in the right order before execute your callable.

```
$callable = new Callback(
    function (array $array, TypeTwo $typeTwo, $string, $int, TypeThree $typeThree, $optional = 42) {
        // My callable body
    }
);
$callable(array(), new TypeTwo(), new TypeThree(), 'string', 123);
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity36

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity59

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~182 days

Total

2

Last Release

4002d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/154023?v=4)[Henrique Moody](/maintainers/henriquemoody)[@henriquemoody](https://github.com/henriquemoody)

---

Top Contributors

[![henriquemoody](https://avatars.githubusercontent.com/u/154023?v=4)](https://github.com/henriquemoody "henriquemoody (17 commits)")

---

Tags

callableclosurecallback

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/phpfluent-callback/health.svg)

```
[![Health](https://phpackages.com/badges/phpfluent-callback/health.svg)](https://phpackages.com/packages/phpfluent-callback)
```

###  Alternatives

[php-di/invoker

Generic and extensible callable invoker

26857.8M56](/packages/php-di-invoker)[winzou/state-machine

A very lightweight yet powerful PHP state machine

52113.7M18](/packages/winzou-state-machine)[zenstruck/callback

Callable wrapper to validate and inject arguments.

569.6M4](/packages/zenstruck-callback)[rybakit/arguments-resolver

ArgumentsResolver allows you to determine the arguments to pass to a function or method.

26107.7k7](/packages/rybakit-arguments-resolver)[raphhh/trex-reflection

Reflection helpers for callables and types

14324.0k10](/packages/raphhh-trex-reflection)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
