PHPackages                             arielespinoza07/php-introspector - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. arielespinoza07/php-introspector

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

arielespinoza07/php-introspector
================================

Modern, type-safe PHP reflection library with comprehensive metadata extraction, member source tracking, DocBlock parsing, and caching support

v1.0.0(6mo ago)00MITPHPPHP ^8.3CI passing

Since Nov 13Pushed 6mo agoCompare

[ Source](https://github.com/ArielEspinoza07/php-introspector)[ Packagist](https://packagist.org/packages/arielespinoza07/php-introspector)[ RSS](/packages/arielespinoza07-php-introspector/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

PHP Introspector
================

[](#php-introspector)

A modern, type-safe PHP reflection library that extracts comprehensive metadata from classes, including properties, methods, constants, DocBlocks, and more.

[![PHP Version](https://camo.githubusercontent.com/ef0054230522e542bc1f908ac005c6c75888dea255bac910f9015e12095e31d7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d626c7565)](https://www.php.net/)[![License](https://camo.githubusercontent.com/f8df3091bbe1149f398a5369b2c39e896766f9f6efba3477c63e9b4aa940ef14/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d677265656e)](LICENSE)[![CI](https://github.com/ArielEspinoza07/php-introspector/actions/workflows/ci.yml/badge.svg)](https://github.com/ArielEspinoza07/php-introspector/actions/workflows/ci.yml)[![Packagist Version](https://camo.githubusercontent.com/2275afbcaad15a8d182efe69300e9a4e0c46f2e922d2728408e9a21dce552a5d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617269656c657370696e6f7a6130372f7068702d696e74726f73706563746f72)](https://packagist.org/packages/arielespinoza07/php-introspector)[![Packagist Downloads](https://camo.githubusercontent.com/1c1df9d58fc917db39e6a51ec9a4052738f56c10ef0629c6c959dd57a31320eb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617269656c657370696e6f7a6130372f7068702d696e74726f73706563746f72)](https://packagist.org/packages/arielespinoza07/php-introspector)

Features
--------

[](#features)

- 🔍 **Complete Class Metadata** - Extract all information about classes, interfaces, traits, and enums
- 📍 **Member Source Tracking** - Know exactly where each member comes from (trait, parent, interface, or self)
- 📝 **Rich DocBlock Parsing** - Full support for `@param`, `@return`, `@var`, `@throws`, and custom tags
- 🎯 **Type Resolution** - Handles union types, intersection types, and special types (`self`, `parent`, `static`)
- 🏷️ **Attributes Support** - PHP 8+ attributes with arguments
- 🔒 **Visibility &amp; Modifiers** - Track public/protected/private, static, readonly, final, abstract
- 💾 **Optional Caching** - Built-in PSR-16 compatible caching layer
- 🎨 **Value Objects** - Immutable, type-safe metadata structures
- 🔧 **PHP 8.3+ Ready** - Leverages modern PHP features

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

[](#installation)

```
composer require arielespinoza07/php-introspector
```

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

[](#quick-start)

```
use Introspector\Reader;

$reader = new Reader();
$metadata = $reader->read(MyClass::class);

// Access class information
echo $metadata->class->name;
echo $metadata->class->type->value;
echo $metadata->class->modifier->isFinal;

// Access properties with source tracking
foreach ($metadata->properties as $property) {
    echo $property->name;
    echo $property->type?->name;
    echo $property->declaringSource->type->value; // "self", "trait", "parent", "interface"
}

// Access methods
foreach ($metadata->methods as $method) {
    echo $method->name;
    echo $method->returnType?->name;
    echo $method->docBlock?->summary;
}

// Access constants
foreach ($metadata->constants as $constant) {
    echo $constant->name;
    echo $constant->value;
    echo $constant->visibility->value;
}
```

Documentation
-------------

[](#documentation)

### Getting Started

[](#getting-started)

- **[Installation](docs/installation.md)** - Requirements and setup
- **[Core Concepts](docs/core-concepts.md)** - Understanding the metadata structure

### Key Features

[](#key-features)

- **[Member Source Tracking](docs/member-source-tracking.md)** ⭐ **NEW** - Track where members originate
- **[DocBlocks](docs/docblocks.md)** - Parse and access DocBlock information
- **[Type System](docs/type-system.md)** - Work with PHP types (union, intersection, nullable, generics)
- **[Attributes](docs/attributes.md)** - PHP 8+ attributes support
- **[Constants](docs/constants.md)** - Class constants with visibility and types

### Advanced Topics

[](#advanced-topics)

- **[Traits and Inheritance](docs/traits-and-inheritance.md)** - Working with traits and class hierarchies
- **[Caching](docs/caching.md)** - Performance optimization with caching
- **[JSON Output](docs/json-output.md)** - Export metadata as JSON
- **[Best Practices](docs/best-practices.md)** - Performance tips and patterns

Member Source Tracking
----------------------

[](#member-source-tracking)

**NEW FEATURE** - Track the origin of every class member:

```
use Introspector\Enums\SourceType;

foreach ($metadata->properties as $property) {
    match ($property->declaringSource->type) {
        SourceType::Self_ => echo "{$property->name} declared in this class",
        SourceType::Trait_ => echo "{$property->name} from {$property->declaringSource->shortName} trait",
        SourceType::Parent_ => echo "{$property->name} inherited from parent",
        SourceType::Interface_ => echo "{$property->name} from interface",
    };
}
```

[Learn more about Member Source Tracking →](docs/member-source-tracking.md)

Performance
-----------

[](#performance)

PHP Introspector is designed for production use with built-in caching:

```
use Introspector\Cache\CachedReader;
use Introspector\Cache\ArrayCache;

$cache = new ArrayCache();
$cachedReader = new CachedReader(new Reader(), $cache);

// First call: ~5-15ms
$metadata = $cachedReader->read(User::class);

// Subsequent calls: ~0.05-0.1ms (100x faster!)
$metadata = $cachedReader->read(User::class);
```

[Learn more about Caching →](docs/caching.md)

Real-World Example
------------------

[](#real-world-example)

```
trait TimestampTrait
{
    private ?DateTimeImmutable $createdAt = null;
    public function touch(): void { /* ... */ }
}

interface Jsonable
{
    public function toJson(): string;
}

class User implements Jsonable
{
    use TimestampTrait;

    private string $name;
    public function toJson(): string { /* ... */ }
}

$reader = new Reader();
$metadata = $reader->read(User::class);

foreach ($metadata->properties as $property) {
    echo "{$property->name}: {$property->declaringSource->type->value}\n";
}
// Output:
// createdAt: trait (from TimestampTrait)
// name: self

foreach ($metadata->methods as $method) {
    echo "{$method->name}: {$method->declaringSource->type->value}\n";
}
// Output:
// touch: trait (from TimestampTrait)
// toJson: interface (from Jsonable)
```

Requirements
------------

[](#requirements)

- PHP 8.3 or higher

Testing
-------

[](#testing)

The library includes comprehensive test fixtures demonstrating all features:

```
composer test
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please ensure:

1. PHP 8.3+ compatibility
2. Type safety (strict types)
3. PHPDoc for all public APIs
4. Tests for new features

License
-------

[](#license)

MIT License. See [LICENSE](LICENSE) for details.

Credits
-------

[](#credits)

Built with ❤️ by [Ariel Espinoza](https://github.com/ArielEspinoza07).

---

**Need help?** [Open an issue](https://github.com/ArielEspinoza07/php-introspector/issues) | [Read the docs](docs/)

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance69

Regular maintenance activity

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity50

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

Unknown

Total

1

Last Release

180d ago

### Community

Maintainers

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

---

Top Contributors

[![ArielEspinoza07](https://avatars.githubusercontent.com/u/9816498?v=4)](https://github.com/ArielEspinoza07 "ArielEspinoza07 (115 commits)")

---

Tags

introspectionmetadataphpphp8reflectionreflectiondocblockmetadataattributesphp8type-safeintrospectionclass-metadatatrait-detection

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/arielespinoza07-php-introspector/health.svg)

```
[![Health](https://phpackages.com/badges/arielespinoza07-php-introspector/health.svg)](https://phpackages.com/packages/arielespinoza07-php-introspector)
```

###  Alternatives

[phpdocumentor/reflection-common

Common reflection classes used by phpdocumentor to reflect the code structure

9.1k706.8M26](/packages/phpdocumentor-reflection-common)[symfony/property-access

Provides functions to read and write from/to an object or array using a simple string notation

2.8k295.3M2.5k](/packages/symfony-property-access)[minime/annotations

The KISS PHP annotations library

229378.6k37](/packages/minime-annotations)[jetbrains/phpstorm-attributes

PhpStorm specific attributes

41416.0M647](/packages/jetbrains-phpstorm-attributes)[phpdocumentor/reflection

Reflection library to do Static Analysis for PHP Projects

12521.4M109](/packages/phpdocumentor-reflection)[php-di/phpdoc-reader

PhpDocReader parses @var and @param values in PHP docblocks (supports namespaced class names with the same resolution rules as PHP)

7431.6M55](/packages/php-di-phpdoc-reader)

PHPackages © 2026

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