PHPackages                             mf/callback-parser - 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. mf/callback-parser

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

mf/callback-parser
==================

PHP parser for arrow functions

2.1.0(7y ago)028.9k1MITPHPPHP ^7.1CI failing

Since Sep 5Pushed 5y ago1 watchersCompare

[ Source](https://github.com/MortalFlesh/CallbackParser)[ Packagist](https://packagist.org/packages/mf/callback-parser)[ RSS](/packages/mf-callback-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (5)Versions (7)Used By (0)

CallbackParser
==============

[](#callbackparser)

[![Latest Stable Version](https://camo.githubusercontent.com/3f4219832b48e2ca7de19b042d5033e40f894e7c9cd6f0aefbf34e349919bfb8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d662f63616c6c6261636b2d7061727365722e737667)](https://packagist.org/packages/mf/callback-parser)[![Build Status](https://camo.githubusercontent.com/b82a62e4ec22f5e079a4ad51dd9508ef1b6a3b94bda4acacb55c24052c0af5c4/68747470733a2f2f7472617669732d63692e6f72672f4d6f7274616c466c6573682f43616c6c6261636b5061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/MortalFlesh/CallbackParser)[![Coverage Status](https://camo.githubusercontent.com/50a20c056dd8d4101bc0fbf98e98d426cd72244ee8ff82d85e60c9e7cebaa511/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f4d6f7274616c466c6573682f43616c6c6261636b5061727365722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/MortalFlesh/CallbackParser?branch=master)[![Total Downloads](https://camo.githubusercontent.com/a0bb21329f319e1af1281edb7ff325cc0fdac5deac3b948b45215f1923cc8ad3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d662f63616c6c6261636b2d7061727365722e737667)](https://packagist.org/packages/mf/callback-parser)[![License](https://camo.githubusercontent.com/f5dfb7dc37aac64a0c1b9100439ce920c5b03b9feaea1b313adbae792342e327/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6d662f63616c6c6261636b2d7061727365722e737667)](https://packagist.org/packages/mf/callback-parser)

PHP parser for arrow functions

> This library is no longer supported, since the arrow functions are natively in PHP 7.4 -

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Arrow Functions](#arrow-functions)
- [How does it work](#how-does-it-work)
- [Possibly WTF?](#wtf)
- [80:20 - Simple](#80-20)

Requirements
----------------------------------------------------

[](#requirements)

- PHP 7.1
- `eval()` function for parsing [Arrow Functions](#arrow-functions)

Installation:
-----------------------------------------------------

[](#installation)

```
composer require mf/callback-parser

```

Arrow Functions
----------------------------------------------------------

[](#arrow-functions)

### Usage:

[](#usage)

```
$callbackParser = new CallbackParser();
$callback = $callbackParser->parseArrowFunction('($a, $b) => $a + $b');

var_dump($callback(2, 3));  // int 5
```

### With Custom Exception

[](#with-custom-exception)

```
$callbackParser = new CallbackParser(App\MyCustomException::class);

$callbackParser->parseArrowFunction('invalid');  // throws App\MyCustomException
```

How does it work?
-------------------------------------------------------------

[](#how-does-it-work)

- it parses function from string and evaluate it with `eval()`

Possibly WTF?
--------------------------------------------

[](#possibly-wtf)

This parser can parse an arrow function into PHP to be execute as usual. But this process could be a little bit more complex than just `eval` it. You can check `CallbackParserTest::provideInvalidFunction()` for examples.

### Namespaces of parameters

[](#namespaces-of-parameters)

For example namespace of class for given parameter type.

```
(SimpleEntity $entity) => $entity->getId()
```

This example above shows an `INVALID` arrow function to be parsed (yet?). Theres more reasons for this is an `invalid` one:

- callback is parsed and `eval`ed elsewhere of scope, where you give such a callback
- so `CallbackParser` does not know `SimpleEntity` full class name

There is more ways to 'fix' it, like:

- you can register a class map of allowed parameter types and parser could find a relevant one and use a full class name from the map, but IMHO this could be more complex than it should be
- parser could also find a relevant class in you entire project and magically use one of the most relevant, but it's a dark magic and I'd rather avoid it

#### Question is - is it really necessary?

[](#question-is---is-it-really-necessary)

I dont think so. Because PHP is quite powerful (`weak`) and allows you to use class methods of an object even if you don't know what they are. But since the original purpose of this parser was to parse a callbacks on [Collections](https://github.com/MortalFlesh/MFCollectionsPHP), you have other ways to know and verify a object type in parameter, so you can simply use those methods right away.

```
$list = new Generic\ListCollection(SimpleEntity::class);
$list->add(new SimpleEntity(1));
$list->add(new SimpleEntity(2));

$ids = $list->map('($entity) => $entity->getId()');

var_dump($ids);

//array (size=2)
//  0 => int 1
//  1 => int 2
```

Simple simpler and complex still simply - 80:20
--------------------------------------------------------------------------------

[](#simple-simpler-and-complex-still-simply---8020)

IMHO this parser allows you to parse simple functions simply, and you can still write a complex functions like PHP allows you.

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~157 days

Recently: every ~197 days

Total

6

Last Release

2745d ago

Major Versions

1.0.1 → 2.0.02017-06-16

PHP version history (3 changes)1.0.0PHP &gt;=5.5 || &gt;=7.0

2.0.0PHP &gt;=7.1

2.0.1PHP ^7.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bdf0b9957c08a48e70a52fce74fc4f1add30b12d442450d5e2b48854fc98b21?d=identicon)[MortalFlesh](/maintainers/MortalFlesh)

---

Top Contributors

[![MortalFlesh](https://avatars.githubusercontent.com/u/6317184?v=4)](https://github.com/MortalFlesh "MortalFlesh (37 commits)")

---

Tags

arrow-functionscallbackphp-parserwtf

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[morilog/jalali

This Package helps developers to easily work with Jalali (Shamsi or Iranian) dates in PHP applications, based on Jalali (Shamsi) DateTime class.

9201.2M45](/packages/morilog-jalali)[bruli/php-git-hooks

Git hooks for PHP projects.

675370.8k5](/packages/bruli-php-git-hooks)[nikolaposa/version

Value Object that represents a SemVer-compliant version number.

1406.4M16](/packages/nikolaposa-version)[prooph/common

Common classes used across prooph packages

852.2M26](/packages/prooph-common)[funeralzone/valueobjects

A PHP 7.1 value objects helper library.

66643.3k22](/packages/funeralzone-valueobjects)[tomasnorre/crawler

Crawler extension for TYPO3

58397.5k1](/packages/tomasnorre-crawler)

PHPackages © 2026

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