PHPackages                             princejohnsantillan/reflect - 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. princejohnsantillan/reflect

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

princejohnsantillan/reflect
===========================

Clearer API for PHP Attributes and Reflection.

1.1.0(1y ago)1610.9k↑50%[2 issues](https://github.com/princejohnsantillan/reflect/issues)MITPHPPHP ^8.1

Since Sep 23Pushed 1y ago1 watchersCompare

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

READMEChangelog (2)Dependencies (5)Versions (13)Used By (0)

[![Reflect](https://private-user-images.githubusercontent.com/60916966/370953327-eec2f4f4-7fed-4cbc-b7e0-81fc9542505c.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ4OTY3MjgsIm5iZiI6MTc3NDg5NjQyOCwicGF0aCI6Ii82MDkxNjk2Ni8zNzA5NTMzMjctZWVjMmY0ZjQtN2ZlZC00Y2JjLWI3ZTAtODFmYzk1NDI1MDVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzMwVDE4NDcwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMwMmI4NWYxNDY1MGE5YzBhMDRiYzVkMmM2NzI1MTgxZWJlMTkxOWM2N2UyNGRlMjY4ZTliZjRmMDE2Zjk0ZGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jIrKpmmjvhc-Wbf93s2ElwcOLc57ib2impgWBArH2mY)](https://private-user-images.githubusercontent.com/60916966/370953327-eec2f4f4-7fed-4cbc-b7e0-81fc9542505c.png?jwt=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NzQ4OTY3MjgsIm5iZiI6MTc3NDg5NjQyOCwicGF0aCI6Ii82MDkxNjk2Ni8zNzA5NTMzMjctZWVjMmY0ZjQtN2ZlZC00Y2JjLWI3ZTAtODFmYzk1NDI1MDVjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNjAzMzAlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjYwMzMwVDE4NDcwOFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWMwMmI4NWYxNDY1MGE5YzBhMDRiYzVkMmM2NzI1MTgxZWJlMTkxOWM2N2UyNGRlMjY4ZTliZjRmMDE2Zjk0ZGYmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.jIrKpmmjvhc-Wbf93s2ElwcOLc57ib2impgWBArH2mY)

Requirement
-----------

[](#requirement)

PHP 8.1 or higher

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

[](#installation)

```
composer require princejohnsantillan/reflect
```

Example
-------

[](#example)

BEFORE:

```
enum Plan: string{
    case FREE = 'free';
    case HOBBY = 'hobby';
    case PRO = 'professional';
    case TEAM = 'team';
    case ENTERPRISE = 'enterprise';

    public function price(): int {
        return match($this){
            static::FREE => 0,
            static::HOBBY => 10,
            static::PRO => 20,
            static::TEAM => 50,
            static::ENTERPRISE = 200
        };
    }

    public function color(): string {
        return match($this){
            static::FREE => 'yellow',
            static::HOBBY => 'orange',
            static::PRO => 'blue',
            static::TEAM => 'silver',
            static::ENTERPRISE = 'gold'
        };
    }
}
```

AFTER:

```
use PrinceJohn\Reflect\Traits\HasEnumTarget;

#[Attribute(Attribute::TARGET_CLASS_CONSTANT)]
class Price{
    use HasEnumTarget;

    public function __construct(public int $price) {}
}
```

```
use PrinceJohn\Reflect\Traits\HasEnumTarget;

#[Attribute(Attribute::TARGET_CLASS_CONSTANT)]
class Color{
    use HasEnumTarget;

    public function __construct(public string $color) {}
}
```

```
use PrinceJohn\Reflect\Enum\Reflect;

enum Plan: string{
    #[Price(0)]
    #[Color('yellow')]
    case FREE = 'free';

    #[Price(10)]
    #[Color('orange')]
    case HOBBY = 'hobby';

    #[Price(20)]
    #[Color('blue')]
    case PRO = 'professional';

    #[Price(50)]
    #[Color('silver')]
    case TEAM = 'team';

    #[Price(200)]
    #[Color('gold')]
    case ENTERPRISE = 'enterprise';

    public function price(): int {
        // Demonstrating usage via the Reflect class
        return Reflect::on($this)
            ->getAttributeInstance(Price::class)
            ->price;
    }

    public function color(): string {
        // Demonstrating usage via the HasEnumTarget trait
        return Color::onEnum($this)->color;
    }
}
```

Note

Alternatively, just return the attribute class, that way you can have more functionality at your disposal.

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance35

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

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

Total

12

Last Release

582d ago

Major Versions

0.3.0 → 1.0.02024-09-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/4eff78899d39d79e9eaf65df18ae55e18ff4be026524d311fdb178f9f2f1d0df?d=identicon)[princejohnsantillan](/maintainers/princejohnsantillan)

---

Top Contributors

[![princejohnsantillan](https://avatars.githubusercontent.com/u/60916966?v=4)](https://github.com/princejohnsantillan "princejohnsantillan (33 commits)")

---

Tags

hacktoberfestenumreflectionattributereflect

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/princejohnsantillan-reflect/health.svg)

```
[![Health](https://phpackages.com/badges/princejohnsantillan-reflect/health.svg)](https://phpackages.com/packages/princejohnsantillan-reflect)
```

###  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)[myclabs/php-enum

PHP Enum implementation

2.7k227.9M635](/packages/myclabs-php-enum)[dasprid/enum

PHP 7.1 enum implementation

379146.0M11](/packages/dasprid-enum)[spatie/enum

PHP Enums

84429.1M68](/packages/spatie-enum)[marc-mabe/php-enum

Simple and fast implementation of enumerations with native PHP

49444.8M97](/packages/marc-mabe-php-enum)

PHPackages © 2026

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