PHPackages                             simpletools/functionparser - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. simpletools/functionparser

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

simpletools/functionparser
==========================

Function parser for PHP functions, methods, and closures

1.0.1(2y ago)043.1k↓38.1%1MITPHPPHP &gt;=7.4

Since Feb 16Pushed 2y agoCompare

[ Source](https://github.com/getsimpletools/FunctionParser)[ Packagist](https://packagist.org/packages/simpletools/functionparser)[ Docs](https://github.com/getsimpletools/FunctionParser)[ RSS](/packages/simpletools-functionparser/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (3)Used By (1)

FunctionParser
==============

[](#functionparser)

The PHP Function Parser library by Jeremy Lindblom.

[![Build Status](https://camo.githubusercontent.com/ad30c9472905187f55c0d8e100de782a2416c91e8d78eab7cd89a574fd9484ff/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6a6572656d65616d69612f46756e6374696f6e5061727365722e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/jeremeamia/FunctionParser)

Purpose
-------

[](#purpose)

The PHP FunctionParser provides the ability to parse and retrieve the code defining an existing function as a string. This can be used in clever ways to generate documentation or example code or even to [serialize a closure](https://github.com/jeremeamia/super_closure).

The class also allows you to get information about the function like the parameter names and the names and values of variables in the `use` statement of a closure.

General Use
-----------

[](#general-use)

The FunctionParser relies on the Reflection API and also on the PHP tokenizer (`token_get_all()`), so PHP must be compiled with the `--enable-tokenizer` flag in order for the tokenizer to be available.

Here is a small example of how it works:

```
use FunctionParser\FunctionParser;

$foo = 2;
$closure = function($bar) use($foo) {
    return $foo + $bar;
};

$parser = new FunctionParser(new \ReflectionFunction($closure));
$code   = $parser->getCode();
```

You can also use the `fromCallable` factory method as a convenient way to generate the reflected function automatically from any PHP callable:

```
$parser = FunctionParser::fromCallable(function($foo) {echo $foo . 'bar';});
$parser = FunctionParser::fromCallable('Foo::bar');
$parser = FunctionParser::fromCallable(array('Foo', 'bar'));
```

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

[](#installation)

The FunctionParser relies on the Reflection API and also on the PHP tokenizer (`token_get_all()`), so PHP must be compiled with the `--enable-tokenizer` flag in order for the tokenizer to be available.

Requirements:

- **PHP 5.3.2+**
- **PHPUnit** for tests
- **Composer** for consuming FunctionParser as a dependency

To install FunctionParser as a dependency of your project using Composer, please add the following to your `composer.json` config file.

```
{
    "require": {
        "jeremeamia/FunctionParser": "*"
    }
}
```

Then run `php composer.phar install --install-suggests` from your project's root directory to install the FunctionParser.

Building
--------

[](#building)

There is a `buid.xml` file that you can use to generate test coverage reports, documenation, and code analytics. The current file is designed to be used with `ant`, but I will be migrating this to `phing` sometime soon. More on this later.

The test suite and code coveage report are currently setup to run in Travis CI. \[See FunctionParser on Travis CI\] [travis-ci](http://travis-ci.org/jeremeamia/FunctionParser)

Links
-----

[](#links)

- [FunctionParser on Travis CI](http://travis-ci.org/jeremeamia/FunctionParser)
- [FunctionParser on Packagist](http://packagist.org/packages/jeremeamia/FunctionParser)
- [FunctionParser on Ohloh](https://www.ohloh.net/p/php-function-parser)

###  Health Score

29

—

LowBetter than 58% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 82% 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 ~0 days

Total

2

Last Release

844d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/195465?v=4)[Marcin](/maintainers/marcinrosinski)[@marcinrosinski](https://github.com/marcinrosinski)

---

Top Contributors

[![jeremeamia](https://avatars.githubusercontent.com/u/107867?v=4)](https://github.com/jeremeamia "jeremeamia (41 commits)")[![GrahamCampbell](https://avatars.githubusercontent.com/u/2829600?v=4)](https://github.com/GrahamCampbell "GrahamCampbell (6 commits)")[![ciaran-moore](https://avatars.githubusercontent.com/u/75904891?v=4)](https://github.com/ciaran-moore "ciaran-moore (2 commits)")[![MAXakaWIZARD](https://avatars.githubusercontent.com/u/1138453?v=4)](https://github.com/MAXakaWIZARD "MAXakaWIZARD (1 commits)")

---

Tags

parserclosurefunctiontokenizer

### Embed Badge

![Health badge](/badges/simpletools-functionparser/health.svg)

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

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k936.5M2.3k](/packages/nikic-php-parser)[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k942.7M149](/packages/doctrine-lexer)[opis/closure

A library that can be used to serialize closures (anonymous functions) and arbitrary data.

2.6k233.3M312](/packages/opis-closure)[masterminds/html5

An HTML5 parser and serializer.

1.8k260.4M292](/packages/masterminds-html5)[matomo/device-detector

The Universal Device Detection library, that parses User Agents and detects devices (desktop, tablet, mobile, tv, cars, console, etc.), clients (browsers, media players, mobile apps, feed readers, libraries, etc), operating systems, devices, brands and models.

3.5k25.3M161](/packages/matomo-device-detector)[jeremeamia/functionparser

Function parser for PHP functions, methods, and closures

48172.5k6](/packages/jeremeamia-functionparser)

PHPackages © 2026

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