Are you happy with your logging solution? Would you help us out by taking a 30-second survey? Click here


A Control Flow Graph implementation in PHP

Subscribe to updates I use php-cfg

Statistics on php-cfg

Number of watchers on Github 101
Number of open issues 9
Average time to close an issue 2 days
Main language PHP
Average time to merge a PR about 11 hours
Open pull requests 5+
Closed pull requests 6+
Last commit almost 2 years ago
Repo Created over 4 years ago
Repo Last Updated almost 2 years ago
Size 396 KB
Organization / Authorircmaxell
Page Updated
Do you use php-cfg? Leave a review!
View open issues (9)
View php-cfg activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating php-cfg for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)

Build Status


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).


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

$parser = new PHPCfg\Parser(
    (new PhpParser\ParserFactory)->create(PhpParser\ParserFactory::PREFER_PHP7)

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

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

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

$dumper = new PHPCfg\Printer\Text();
echo $dumper->printScript($script);
php-cfg open issues Ask a question     (View All Issues)
  • over 3 years Referenced parameters not showing as referenced
  • over 3 years Function uses global variable causes inconsistency in variable id
  • over 3 years [Meta] Documentation
  • over 3 years Assertion fail when returning an anonymous function.
  • over 3 years Provide CFG numberings
  • over 3 years Desugar multi-argument isset() into single-argument isset()
php-cfg open pull requests (View All Pulls)
  • Fix bug about the "elseif" stmt
  • Proof of Concept for exception flow with finally's
  • NameResolver soft fail for invalid doc comments
  • Make compatible with nikic/php-parser:3.0
  • Fixed parents for blocks from Expr\ErrorSuppress
php-cfg list of languages used
Other projects in PHP