PHPackages                             type-lang/reader - 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. type-lang/reader

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

type-lang/reader
================

Library for reading TypeLang AST nodes from types exposed by PHP Reflection objects

1.1.1(1y ago)65.6kMITPHPPHP ^8.1CI passing

Since Apr 1Pushed 1y ago1 watchersCompare

[ Source](https://github.com/php-type-language/reader)[ Packagist](https://packagist.org/packages/type-lang/reader)[ RSS](/packages/type-lang-reader/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (7)Versions (9)Used By (0)

[ ![](https://github.com/php-type-language/.github/raw/master/assets/dark.png?raw=true)](https://github.com/php-type-language)---

 [![PHP 8.1+](https://camo.githubusercontent.com/204f5d78b32fe5b650e7f6c8a63f9ff3a82b4b7212cdf7185ade8c3ea64ca6f6/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7265616465722f726571756972652f7068703f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/reader) [![Latest Stable Version](https://camo.githubusercontent.com/e6925323bb4221f8d89db4d6397c7122473b5096989de104d1c7bbe72b2ee671/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7265616465722f76657273696f6e3f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/reader) [![Latest Unstable Version](https://camo.githubusercontent.com/03c046dd36e2acbcee54e572e6b75fec387089056f0a2e3a280ff1763620097d/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7265616465722f762f756e737461626c653f7374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/type-lang/reader) [![License MIT](https://camo.githubusercontent.com/0c3b37980bf0d5e9c38276446252c75a1b4cd56f08c46f5b91b95af5f845a966/68747470733a2f2f706f7365722e707567782e6f72672f747970652d6c616e672f7265616465722f6c6963656e73653f7374796c653d666f722d7468652d6261646765)](https://raw.githubusercontent.com/php-type-language/reader/blob/master/LICENSE)

 [![](https://github.com/php-type-language/reader/workflows/tests/badge.svg)](https://github.com/php-type-language/reader/actions)

Provides a set of methods for converting PHP Reflection objects into the TypeLang AST Nodes.

Read [documentation pages](https://typelang.dev) for more information.

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

[](#installation)

TypeLang Reader is available as Composer repository and can be installed using the following command in a root of your project:

```
composer require type-lang/reader
```

Quick Start
-----------

[](#quick-start)

```
$reader = new \TypeLang\Reader\ReflectionReader();

$node = $reader->findFunctionType(
    function: new \ReflectionFunction(function(): void {}),
);

var_dump($node);
```

**Expected Output:**

```
TypeLang\Parser\Node\Stmt\NamedTypeNode {
  +offset: 0
  +name: TypeLang\Parser\Node\Name {
    +offset: 0
    -parts: array:1 [
      0 => TypeLang\Parser\Node\Identifier {
        +offset: 0
        +value: "void"
      }
    ]
  }
  +arguments: null
  +fields: null
}

```

### Creating From Reflection

[](#creating-from-reflection)

```
$class = new \ReflectionClass(Path\To\Example::class);

// Printer component provided by "type-lang/printer" package.
$printer = new \TypeLang\Printer\PrettyPrinter();

$converter = new \TypeLang\Reader\ReflectionReader();

// Dump all constants with its types.
foreach ($class->getReflectionConstants() as $constant) {
    // Creates type node AST from a constant's type.
    if ($type = $converter->findConstantType($constant)) {
        echo 'const ' . $constant->name . ' has type ' . $printer->print($type) . "\n";
    }
}

// Dump all properties with its types.
foreach ($class->getProperties() as $property) {
    // Creates type node AST from a property's type.
    if ($type = $converter->findPropertyType($property)) {
        echo 'property ' . $property->name . ' has type ' . $printer->print($type) . "\n";
    }
}

// Dump all methods with its types.
foreach ($class->getMethods() as $method) {
    // Creates type node AST from any function's return type.
    if ($type = $converter->findFunctionType($method)) {
        echo 'function ' . $method->name . ' has type ' . $printer->print($type) . "\n";
    }

    // Creates type node AST from a parameter's type.
    foreach ($method->getParameters() as $parameter) {
        if ($type = $converter->findParameterType($parameter)) {
            echo 'parameter ' . $parameter->name . ' has type ' . $printer->print($type) . "\n";
        }
    }
}
```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance41

Moderate activity, may be stable

Popularity25

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

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

Recently: every ~67 days

Total

8

Last Release

493d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/150420?v=4)[Ruslan Sharipov](/maintainers/Serafim)[@serafim](https://github.com/serafim)

---

Tags

astconverterphpreaderreflectiontypesphplanguageparserreflectionconverter

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/type-lang-reader/health.svg)

```
[![Health](https://phpackages.com/badges/type-lang-reader/health.svg)](https://phpackages.com/packages/type-lang-reader)
```

###  Alternatives

[doctrine/lexer

PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.

11.2k910.8M118](/packages/doctrine-lexer)[simplehtmldom/simplehtmldom

A fast, simple and reliable HTML document parser for PHP.

1921.3M14](/packages/simplehtmldom-simplehtmldom)[type-lang/parser

Library for parsing and validating TypeLang syntax and converting it into AST nodes

5158.4k6](/packages/type-lang-parser)[corveda/php-sandbox

A PHP library that can be used to run PHP code in a sandboxed environment

23483.5k2](/packages/corveda-php-sandbox)[sbsaga/toon

🧠 TOON for Laravel — a compact, human-readable, and token-efficient data format for AI prompts &amp; LLM contexts. Perfect for ChatGPT, Gemini, Claude, Mistral, and OpenAI integrations (JSON ⇄ TOON).

6115.6k](/packages/sbsaga-toon)[goetas/xsd2php-runtime

Convert XSD (XML Schema) definitions into PHP classes

493.3k](/packages/goetas-xsd2php-runtime)

PHPackages © 2026

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