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

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

spatie/php-attribute-reader
===========================

A clean API for working with PHP attributes

1.1.0(2mo ago)80216.4k↑127.1%1[1 PRs](https://github.com/spatie/php-attribute-reader/pulls)9MITPHPPHP ^8.0CI passing

Since Feb 22Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/spatie/php-attribute-reader)[ Packagist](https://packagist.org/packages/spatie/php-attribute-reader)[ Docs](https://github.com/spatie/php-attribute-reader)[ GitHub Sponsors](https://github.com/spatie)[ RSS](/packages/spatie-php-attribute-reader/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (3)Dependencies (1)Versions (5)Used By (9)

A clean API for working with PHP attributes
===========================================

[](#a-clean-api-for-working-with-php-attributes)

[![Latest Version on Packagist](https://camo.githubusercontent.com/8d25e1a338e6cbbcbee3ee95a7906434b593cbec0dfee59349396218f786c599/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f7068702d6174747269627574652d7265616465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/php-attribute-reader)[![GitHub Tests Action Status](https://camo.githubusercontent.com/ad8b65dd6310c62bdf7fe5f1b63759cf090adf1d606754e078890521daa381d3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f7068702d6174747269627574652d7265616465722f72756e2d74657374732d706573742e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/spatie/php-attribute-reader/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/a619fbcc5e1c215c1ae82559bbd93850ee4e5aee6e12c42f31dce46c94e6b4ff/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f7068702d6174747269627574652d7265616465722f6669782d7068702d636f64652d7374796c652d6973737565732d70696e742e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/spatie/php-attribute-reader/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/1372de4bc8660cfe14f52fc063bef7653a43ee50c7bdf0f2de3bcbcd422d11e2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f7068702d6174747269627574652d7265616465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/php-attribute-reader)

PHP 8.0 introduced attributes, but the reflection API to actually read them is verbose and awkward. Want to check if a class has a specific attribute? That's four lines. Want to find every occurrence of an attribute across a class, its methods, properties, constants, and parameters? That's 40+ lines of nested foreach loops.

This package gives you a clean, static API instead:

```
use Spatie\Attributes\Attributes;

// Get a single attribute from a class
$route = Attributes::get(MyController::class, Route::class);

// Check if a class has an attribute
Attributes::has(MyController::class, Route::class); // true

// Read from methods, properties, constants, parameters
Attributes::onMethod(MyController::class, 'index', Route::class);
Attributes::onProperty(User::class, 'email', Column::class);
Attributes::onConstant(Status::class, 'ACTIVE', Label::class);
Attributes::onParameter(MyController::class, 'show', 'id', FromRoute::class);

// Find an attribute everywhere in a class at once
$results = Attributes::find(MyForm::class, Validate::class);

foreach ($results as $result) {
    $result->attribute; // The instantiated attribute
    $result->target;    // The Reflection object
    $result->name;      // e.g. 'email', 'handle.request'
}
```

Every method returns instantiated attribute objects, missing targets return `null` instead of throwing exceptions, and child attributes are matched automatically.

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/b3b68a83dc4b8016d5570892990dabe1694859cd550f4b0e22a5028a4138897e/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f7068702d6174747269627574652d7265616465722e6a70673f743d31)](https://spatie.be/github-ad-click/php-attribute-reader)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#documentation)

All documentation is available [on our documentation site](https://spatie.be/docs/php-attribute-reader).

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

51

—

FairBetter than 96% of packages

Maintenance83

Actively maintained with recent releases

Popularity49

Moderate usage in the ecosystem

Community19

Small or concentrated contributor base

Maturity42

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 95.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 ~0 days

Total

3

Last Release

84d ago

Major Versions

0.0.1 → 1.0.02026-02-22

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7535935?v=4)[Spatie](/maintainers/spatie)[@spatie](https://github.com/spatie)

---

Top Contributors

[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (22 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (1 commits)")

---

Tags

attributesphpspatiereflectionattributesphp-attribute-reader

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/spatie-php-attribute-reader/health.svg)

```
[![Health](https://phpackages.com/badges/spatie-php-attribute-reader/health.svg)](https://phpackages.com/packages/spatie-php-attribute-reader)
```

###  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)[spatie/laravel-package-tools

Tools for creating Laravel packages

945125.5M7.0k](/packages/spatie-laravel-package-tools)[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/macroable

A trait to dynamically add methods to a class

72759.6M64](/packages/spatie-macroable)[spatie/regex

A sane interface for php's built in preg\_\* functions

1.1k17.1M59](/packages/spatie-regex)

PHPackages © 2026

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