PHPackages                             ircmaxell/php-cfg - 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. ircmaxell/php-cfg

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

ircmaxell/php-cfg
=================

A Control Flow Graph implementation for PHP

V0.8.1(10mo ago)247103.3k↑279.7%45[10 issues](https://github.com/ircmaxell/php-cfg/issues)[6 PRs](https://github.com/ircmaxell/php-cfg/pulls)2MITPHPPHP &gt;=7.4CI passing

Since Feb 23Pushed 9mo ago11 watchersCompare

[ Source](https://github.com/ircmaxell/php-cfg)[ Packagist](https://packagist.org/packages/ircmaxell/php-cfg)[ RSS](/packages/ircmaxell-php-cfg/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)Dependencies (4)Versions (11)Used By (2)

[![Build Status](https://github.com/ircmaxell/php-cfg/actions/workflows/main.yml/badge.svg)](https://github.com/ircmaxell/php-cfg/actions)[![Latest Stable Version](https://camo.githubusercontent.com/9a6f615988dae2bf55c2a56596f23ecd564c62dd03dab7159763d459f5f43556/68747470733a2f2f706f7365722e707567782e6f72672f6972636d6178656c6c2f7068702d6366672f762f737461626c65)](https://packagist.org/packages/ircmaxell/php-cfg)

PHP-CFG
=======

[](#php-cfg)

Pure PHP implementation of a control flow graph (CFG) with instructions in static single assignment (SSA) form.

The used SSA construction algorithm is based on "Simple and Efficient Construction of Static Single Assignment Form" by Braun et al. This algorithm constructs SSA form directly from the abstract syntax tree, without going through a non-SSA IR first. If you're looking for dominance frontiers, you won't find them here...

The constructed SSA form is minimal and pure (or is supposed to be).

Usage
-----

[](#usage)

To bootstrap the parser, you need to give it a `PhpParser` instance:

```
$parser = new PHPCfg\Parser(
    (new PhpParser\ParserFactory)->createForNewestSupportedVersion()
);
```

Then, just call parse on a block of code, giving it a filename:

```
$script = $parser->parse(file_get_contents(__FILE__), __FILE__);
```

While not strictly necessary, you likely should also run the Simplifier Visitor via the Traverser to optimize the CFG (remove redundant jumps and blocks, simplify Phi nodes as much as possible, etc). Other visitors exist to help find function and class declarations (`PHPCfg\Visitor\DeclarationFinder`), find function and method calls (`PHPCfg\Visitor\CallFinder`), and find all variables (`PHPCfg\Visitor\VariableFinder`).

You can also implement your own custom `PHPCfg\Visitor` and add it to the traverser in order to apply analysis or transforms to the CFG to achieve different results.

```
$traverser = new PHPCfg\Traverser();
$traverser->addVisitor(new PHPCfg\Visitor\Simplifier());
$traverser->traverse($script);
```

To dump the graph, simply use the built-in dumper:

```
$dumper = new PHPCfg\Printer\Text();
echo $dumper->printScript($script);
```

CLI
---

[](#cli)

You can leverage the CLI binary to generate debug traces of the CFG for any file, or for printing GraphViz visualizations.

```
bin/php-cfg dot -o output.dot path/to/file.php
```

###  Health Score

54

—

FairBetter than 96% of packages

Maintenance55

Moderate activity, may be stable

Popularity52

Moderate usage in the ecosystem

Community31

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~397 days

Total

8

Last Release

321d ago

Major Versions

v0.5.x-dev → v1.0.x-dev2019-03-12

PHP version history (2 changes)v0.5.0PHP ^7.0

v0.6.0PHP &gt;=7.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/c87a667fe5a109ed083ba784409a76f0a18f30b0a05445fbb8ef5e4520b7a6e1?d=identicon)[ircmaxell](/maintainers/ircmaxell)

---

Top Contributors

[![ircmaxell](https://avatars.githubusercontent.com/u/660654?v=4)](https://github.com/ircmaxell "ircmaxell (150 commits)")[![nikic](https://avatars.githubusercontent.com/u/216080?v=4)](https://github.com/nikic "nikic (73 commits)")[![eric-therond](https://avatars.githubusercontent.com/u/11455652?v=4)](https://github.com/eric-therond "eric-therond (49 commits)")[![mwijngaard](https://avatars.githubusercontent.com/u/273701?v=4)](https://github.com/mwijngaard "mwijngaard (14 commits)")[![PavelJurasek](https://avatars.githubusercontent.com/u/1270132?v=4)](https://github.com/PavelJurasek "PavelJurasek (4 commits)")[![LioTree](https://avatars.githubusercontent.com/u/12847578?v=4)](https://github.com/LioTree "LioTree (4 commits)")[![silverfoxy](https://avatars.githubusercontent.com/u/1313190?v=4)](https://github.com/silverfoxy "silverfoxy (2 commits)")[![royopa](https://avatars.githubusercontent.com/u/442991?v=4)](https://github.com/royopa "royopa (2 commits)")[![thegallagher](https://avatars.githubusercontent.com/u/486626?v=4)](https://github.com/thegallagher "thegallagher (2 commits)")[![ovr](https://avatars.githubusercontent.com/u/572096?v=4)](https://github.com/ovr "ovr (2 commits)")[![sergeyklay](https://avatars.githubusercontent.com/u/1256298?v=4)](https://github.com/sergeyklay "sergeyklay (1 commits)")[![SZFsir](https://avatars.githubusercontent.com/u/24249321?v=4)](https://github.com/SZFsir "SZFsir (1 commits)")[![leestephenn](https://avatars.githubusercontent.com/u/4571662?v=4)](https://github.com/leestephenn "leestephenn (1 commits)")[![villfa](https://avatars.githubusercontent.com/u/2891564?v=4)](https://github.com/villfa "villfa (1 commits)")[![fntlnz](https://avatars.githubusercontent.com/u/3083633?v=4)](https://github.com/fntlnz "fntlnz (1 commits)")[![salmonx](https://avatars.githubusercontent.com/u/8596646?v=4)](https://github.com/salmonx "salmonx (1 commits)")[![samnela](https://avatars.githubusercontent.com/u/1852108?v=4)](https://github.com/samnela "samnela (1 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/ircmaxell-php-cfg/health.svg)

```
[![Health](https://phpackages.com/badges/ircmaxell-php-cfg/health.svg)](https://phpackages.com/packages/ircmaxell-php-cfg)
```

###  Alternatives

[deptrac/deptrac

Deptrac is a static code analysis tool that helps to enforce rules for dependencies between software layers.

3.0k8.8M118](/packages/deptrac-deptrac)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[beyondcode/laravel-er-diagram-generator

Generate ER diagrams from your Laravel models.

2.0k1.5M2](/packages/beyondcode-laravel-er-diagram-generator)[roave/backward-compatibility-check

Tool to compare two revisions of a public API to check for BC breaks

6003.7M96](/packages/roave-backward-compatibility-check)[tempest/framework

The PHP framework that gets out of your way.

2.2k34.4k15](/packages/tempest-framework)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4814.0M25](/packages/coenjacobs-mozart)

PHPackages © 2026

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