PHPackages                             dg/parser-reflection - 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. dg/parser-reflection

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

dg/parser-reflection
====================

Provides reflection information, based on raw source

1.3.1(8y ago)43.0k11MITPHPPHP &gt;=5.6.0

Since Nov 22Pushed 6y ago3 watchersCompare

[ Source](https://github.com/dg/parser-reflection)[ Packagist](https://packagist.org/packages/dg/parser-reflection)[ RSS](/packages/dg-parser-reflection/feed)WikiDiscussions master Synced 3w ago

READMEChangelogDependencies (2)Versions (13)Used By (1)

Parser Reflection API Library
-----------------------------

[](#parser-reflection-api-library)

This is fork of great [goaop/parser-reflection](https://github.com/goaop/parser-reflection) library with some modifications.

Parser Reflection API library provides a set of classes that extend original internal Reflection classes, but powered by [PHP-Parser](https://github.com/nikic/PHP-Parser) library thus allowing to create a reflection instance without loading classes into the memory.

This library can be used for analysing the source code for PHP versions 5.5, 5.6, 7.0; for automatic proxy creation and much more.

[![Build Status](https://camo.githubusercontent.com/b1d15c785bc2c26917c9bcad18288717ae7c85df3cc899a631ded9ae5c4892bd/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64672f7061727365722d7265666c656374696f6e2f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dg/parser-reflection/build-status/master)[![Code Coverage](https://camo.githubusercontent.com/26c76aaa08e8b3c401a52a4f42b405bcf60244f4c3473783162e7328023ff602/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64672f7061727365722d7265666c656374696f6e2f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dg/parser-reflection/?branch=master)[![Total Downloads](https://camo.githubusercontent.com/6ae1ecd17bc3a0fdf4478cd8e15485be0885d1a43e6057c67dcbf9f9b200f24e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f64672f7061727365722d7265666c656374696f6e2e737667)](https://packagist.org/packages/dg/parser-reflection)[![Daily Downloads](https://camo.githubusercontent.com/85871f66f445bd2233f51666eb99c881e2efd7dfbe1823a44afc3b109dbc0562/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64642f64672f7061727365722d7265666c656374696f6e2e737667)](https://packagist.org/packages/dg/parser-reflection)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/83252003633e0225c79730765a430006944d20b2052e015f9f03b1d17e0899a0/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f64672f7061727365722d7265666c656374696f6e2f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/dg/parser-reflection/?branch=master)[![SensioLabs Insight](https://camo.githubusercontent.com/dca01aa11834e5b92e7d4319548d0b57ac2e76872b2d4b496be23492f8af9438/68747470733a2f2f696d672e736869656c64732e696f2f73656e73696f6c6162732f692f31666466656539632d383339612d343230392d613266322d3432646164633835393632312e737667)](https://insight.sensiolabs.com/projects/1fdfee9c-839a-4209-a2f2-42dadc859621)[![Minimum PHP Version](https://camo.githubusercontent.com/dd6bad85ee03cf570f4cf82ab69a80396fdbf48050af932f8f23aa551b0d1e5a/687474703a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344253230352e352d3838393242462e737667)](https://php.net/)[![License](https://camo.githubusercontent.com/02b383a30cadcf2917d3336af6653d8903253aa9544c2589e120c887cee16d20/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f64672f7061727365722d7265666c656374696f6e2e737667)](https://packagist.org/packages/dg/parser-reflection)

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

[](#installation)

Library can be installed with Composer. Installation is quite easy:

```
$ composer require dg/parser-reflection
```

Composer will install the library to your project's `vendor/dg/parser-reflection` directory.

Usage
-----

[](#usage)

### Initialization

[](#initialization)

Prior to the first use library can be optionally initialized. If you use Composer for installing packages and loading classes, then you shouldn't worry about initialization, library will be initialized automatically.

If project uses a custom autoloader then you should follow the next steps:

1. Create a new class that implements `\Go\ParserReflection\LocatorInterface`
2. Create an instance of that class and pass it to the `ReflectionEngine::init()` method for initial configuration

### Reflecting concrete classes/methods/properties without loading them

[](#reflecting-concrete-classesmethodsproperties-without-loading-them)

Just use `Go\ParserReflection` package reflection classes like traditional ones:

```
$parsedClass = new \Go\ParserReflection\ReflectionClass(SomeClass::class);
var_dump($parsedClass->getMethods());

$parsedMethod = new \Go\ParserReflection\ReflectionMethod(SomeClass::class, 'someMethod');
echo (string)$parsedMethod;
```

Or you can use an additional classes [`ReflectionFile`](docs/reflection_file.md) and [`ReflectionFileNamespace`](docs/reflection_file_namespace.md) to analyse a raw PHP files:

```
$parsedFile     = new \Go\ParserReflection\ReflectionFile('SomeClass.php');
$fileNameSpaces = $parsedFile->getFileNamespaces();
// We can iterate over namespaces in the file
foreach ($fileNameSpaces as $namespace) {
    $classes = $namespace->getClasses();
    // Iterate over the classes in the namespace
    foreach ($classes as $class) {
        echo "Found class: ", $class->getName(), PHP_EOL;
        // Now let's show all methods in the class
        foreach ($class->getMethods() as $method) {
            echo "Found class method: ", $class->getName(), '::', $method->getName(), PHP_EOL;
        }

        // ...all properties in the class
        foreach ($class->getProperties() as $property) {
            echo "Found class property: ", $class->getName(), '->', $property->getName(), PHP_EOL;
        }
    }
}
```

How it works?
-------------

[](#how-it-works)

To understand how library works let's look at what happens during the call to the `new \Go\ParserReflection\ReflectionClass(SomeClass::class)`

- `\Go\ParserReflection\ReflectionClass` asks reflection engine to give an AST node for the given class name
- Reflection engine asks a locator to locate a filename for the given class
- `ComposerLocator` instance asks the Composer to find a filename for the given class and returns this result back to the reflection engine
- Reflection engine loads the content of file and passes it to the [PHP-Parser](https://github.com/nikic/PHP-Parser) for tokenization and processing
- PHP-Parser returns an AST (Abstract Syntax Tree)
- Reflection engine then analyse this AST to extract specific nodes an wrap them into corresponding reflection classes.

Compatibility
-------------

[](#compatibility)

All parser reflection classes extend PHP internal reflection classes, this means that you can use `\Go\ParserReflection\ReflectionClass` instance in any place that asks for `\ReflectionClass` instance. All reflection methods should be compatible with original ones, providing an except methods that requires object manipulation, such as `invoke()`, `invokeArgs()`, `setAccessible()`, etc. These methods will trigger the autoloading of class and switching to the internal reflection.

###  Health Score

34

—

LowBetter than 75% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community18

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 91.7% 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 ~71 days

Recently: every ~137 days

Total

10

Last Release

3220d ago

Major Versions

0.6.0 → 1.0.0-alpha2015-12-26

PHP version history (2 changes)0.5.0PHP &gt;=5.5.0

1.3.1PHP &gt;=5.6.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/17f266513a3ca97500ec3d85d562b9279c7a6346358fe2b8d90390ece717a027?d=identicon)[david@grudl.com](/maintainers/david@grudl.com)

---

Top Contributors

[![lisachenko](https://avatars.githubusercontent.com/u/640114?v=4)](https://github.com/lisachenko "lisachenko (209 commits)")[![dg](https://avatars.githubusercontent.com/u/194960?v=4)](https://github.com/dg "dg (13 commits)")[![Fedott](https://avatars.githubusercontent.com/u/165486?v=4)](https://github.com/Fedott "Fedott (3 commits)")[![loren-osborn](https://avatars.githubusercontent.com/u/2467372?v=4)](https://github.com/loren-osborn "loren-osborn (1 commits)")[![MaximilianKresse](https://avatars.githubusercontent.com/u/545671?v=4)](https://github.com/MaximilianKresse "MaximilianKresse (1 commits)")[![pdelre](https://avatars.githubusercontent.com/u/1379248?v=4)](https://github.com/pdelre "pdelre (1 commits)")

---

Tags

parserphpreflection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dg-parser-reflection/health.svg)

```
[![Health](https://phpackages.com/badges/dg-parser-reflection/health.svg)](https://phpackages.com/packages/dg-parser-reflection)
```

###  Alternatives

[dedoc/scramble

Automatic generation of API documentation for Laravel applications.

2.1k9.9M89](/packages/dedoc-scramble)[psalm/plugin-laravel

Psalm plugin for Laravel

3345.1M337](/packages/psalm-plugin-laravel)[tempest/framework

The PHP framework that gets out of your way.

2.2k31.1k12](/packages/tempest-framework)[phparkitect/phparkitect

Enforce architectural constraints in your PHP applications

9184.1M24](/packages/phparkitect-phparkitect)[jolicode/automapper

JoliCode AutoMapper

216497.6k10](/packages/jolicode-automapper)[ajthinking/archetype

Programmatically edit PHP and Laravel files.

2723.7M17](/packages/ajthinking-archetype)

PHPackages © 2026

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