PHPackages                             jeremeamia/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. jeremeamia/functionparser

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

jeremeamia/functionparser
=========================

Function parser for PHP functions, methods, and closures

1.0.0(11y ago)48169.7k↓30%8[1 PRs](https://github.com/jeremeamia/FunctionParser/pulls)6MITPHPPHP &gt;=5.3.2

Since Feb 2Pushed 2y ago4 watchersCompare

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

READMEChangelog (1)DependenciesVersions (1)Used By (6)

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

38

—

LowBetter than 85% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community22

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 85.4% 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

Unknown

Total

1

Last Release

4123d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/184fbc398ff1b83855ab8289cd8ce20225d0158c66284b458d2d811546606938?d=identicon)[jeremeamia](/maintainers/jeremeamia)

---

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)")[![MAXakaWIZARD](https://avatars.githubusercontent.com/u/1138453?v=4)](https://github.com/MAXakaWIZARD "MAXakaWIZARD (1 commits)")

---

Tags

parserclosurefunctiontokenizer

### Embed Badge

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

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

###  Alternatives

[nikic/php-parser

A PHP parser written in PHP

17.4k902.6M1.8k](/packages/nikic-php-parser)[doctrine/lexer

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

11.2k910.8M118](/packages/doctrine-lexer)[opis/closure

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

2.6k230.0M284](/packages/opis-closure)[erusev/parsedown

Parser for Markdown.

15.0k151.8M732](/packages/erusev-parsedown)[masterminds/html5

An HTML5 parser and serializer.

1.8k242.8M229](/packages/masterminds-html5)[sabberworm/php-css-parser

Parser for CSS Files written in PHP

1.8k191.2M65](/packages/sabberworm-php-css-parser)

PHPackages © 2026

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