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

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

donquixote/hasty-reflection-parser
==================================

0.0.0.alpha.4(10y ago)021MITPHPPHP &gt;=5.5.0

Since Jan 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/donquixote/hasty-reflection-parser)[ Packagist](https://packagist.org/packages/donquixote/hasty-reflection-parser)[ RSS](/packages/donquixote-hasty-reflection-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (6)Used By (0)

[![Build Status](https://camo.githubusercontent.com/cb450979a00a86c1fbfb1adc4cf77c52ba204df42fe6ff8e0e1b403514741e5f/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f646f6e717569786f74652f68617374792d7265666c656374696f6e2d7061727365722e706e67)](https://travis-ci.org/donquixote/hasty-reflection-parser)

hasty-reflection-parser
=======================

[](#hasty-reflection-parser)

A library that parses PHP code to generate reflection objects.

It is called "hasty", because it skips and omits and ignores a lot of stuff, and only focuses on what one usually wants for e.g. annotation discovery.

Currently it ignores variable declarations, regular statements, function calls, object variables, function declarations, and more.

Use cases:
It is meant for stuff like Annotation discovery like in Doctrine or Drupal 8.

### Partial libraries (as dependencies):

[](#partial-libraries-as-dependencies)

hasty-php-ast:
Abstract syntax tree. This is an incomplete representation of PHP !

hasty-php-parser:
The parser. Turns a PHP string into an AST graph. Based on `token_get_all()`.

hasty-reflection-common:
Classes and interfaces similar to the core reflection API. Contains a working "native" implementation that uses core reflection instead of parsing.

hasty-reflection-parser:
Uses the parser to generate the reflection objects.

### How to use

[](#how-to-use)

First, choose one of the various implementations of `ClassIndexInterface`. E.g.

```
// Use native reflection and native class loader. This means, all files will be *really* included in PHP.
$classIndex = new ClassIndex_Native();

// Files will be parsed AND included.
$classIndex = ClassIndex_Ast::createSemiNative();

// Class files will be parsed, and NOT included.
// Using the currently active Composer class loader/finder. Obviously you need to make sure to get the path right.
$composerClassLoader = include dirname(dirname(__DIR__)) . '/vendor/autoload.php';
$classIndex = ClassIndex_Ast::createWithClassLoader(new ClassLoader_Composer($composerClassLoader));
```

Now you can get class reflection objects as you want.

```
$classReflection = $classIndex->classGetReflection(C::class);
print $classReflection->getDocComment();
```

The ClassIndex makes sure that only one reflection object exists for each class/interface/trait/method.

```
assert($classIndex->classGetReflection(C::class) === $classIndex->classGetReflection(C::class));
print $classReflection->getDocComment();
```

### Performance

[](#performance)

This thing should be quite fast, because the parser skips a lot of stuff. For long method or function bodies, it will simply fast-forward through the tokens, and only count opening and closing brackets!

It does currently NOT do the trick of cutting out the class body PHP. This is because it was made for a use case where we are really interested in the class body.

However, the class body will initially be read in fast mode, to be picked up later, if/when requested. (This is the "lazy" parameter for some classes).

The token array from `token_get_all()` is never sliced or manipulated, which means PHP only needs to pass around the array pointer, not create different versions the array itself.

The length of the token array is not remembered either, instead it is terminated by a unique symbol.

### Status of this library

[](#status-of-this-library)

This is very fresh. Mabye some names will change in the near future!

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

5

Last Release

3780d ago

### Community

Maintainers

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

---

Top Contributors

[![donquixote](https://avatars.githubusercontent.com/u/150032?v=4)](https://github.com/donquixote "donquixote (11 commits)")

### Embed Badge

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

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

###  Alternatives

[mtdowling/jmespath.php

Declaratively specify how to extract elements from a JSON document

2.0k472.8M135](/packages/mtdowling-jmespathphp)[opis/closure

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

2.6k230.0M284](/packages/opis-closure)[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)[michelf/php-markdown

PHP Markdown

3.5k52.4M345](/packages/michelf-php-markdown)[jms/metadata

Class/method/property metadata management in PHP

1.8k152.8M88](/packages/jms-metadata)

PHPackages © 2026

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