john-nguyen09 / php-reflection

:mag_right: Nodejs Reflection API for PHP files based on the php-parser

Home Page:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PHP Reflection

npm version Build Status Coverage Status Gitter

Nodejs Reflection API for PHP files based on the php-parser


npm install php-reflection --save


var reflection = require('php-reflection');
var workspace = new reflection.Repository('/home/devbox/my-project', {
    // actual default options :
    exclude: ['.git', '.svn'],
    include: ['./'],
    ext: [
    scanVars: true,
    scanExpr: true,
    encoding: 'utf8',
    cacheByFileSize: true
var workers = [
Promise.all(workers).then(function() {
    console.log('-- list of functions :');
    workspace.getByType('function').each(function(fn) {
        console.log('Function Name : ',;
        console.log('Located into : ', fn.getFile().name);
        console.log('At line : ', fn.position.start.line);

Read the API docs for more details.

What it can do

  • Fully reflection support (classes, inheritance, documentation blocks)
  • Recursively scan directories and add files to repository
  • Request cross files elements (like retrieving a class)
  • Put in-memory documents structure (with a small memory footprint)
  • You can use a cache engine for the repository
  • It avoids parsing a file that is already in memory and not modified since last parsing
  • Symbols relations (what variable instanciate a class, or who extends that class)
  • A cool (and really fast) requesting engine for retrieving elements

What you could do with it

  • Write a documentation generator
  • Write a static code generator based on relection (like an ORM)
  • Write a code analysis tool (like phpMessDetector)
  • Write a code completion plugin

... if you want to share an idea or your project make a pull request


WIP Disclaimer

This project is actually on it's early alpha stage. It may progress rapidly, so watch the project if you are interested to use it.

ezoic increase your site revenue


:mag_right: Nodejs Reflection API for PHP files based on the php-parser

License:BSD 3-Clause "New" or "Revised" License


Language:JavaScript 97.5%Language:PHP 2.5%