PHPackages                             bakabot/attribute - 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. bakabot/attribute

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

bakabot/attribute
=================

Provides accessors to single-value PHP Attributes.

2.0.1(10mo ago)026MITPHPPHP &gt;=8.0

Since Jul 10Pushed 10mo agoCompare

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

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

bakabot-attribute [![Latest Stable Version](https://camo.githubusercontent.com/85e050db35287d63dde252af9e1afe14f6ce711d88dce22a616bb77bb093542b/68747470733a2f2f706f7365722e707567782e6f72672f62616b61626f742f6174747269627574652f76)](//packagist.org/packages/bakabot/attribute) [![License](https://camo.githubusercontent.com/89ef490d1334a7c6117588177dffdc49c90f272e58bbe41e703f77200a36d69d/68747470733a2f2f706f7365722e707567782e6f72672f62616b61626f742f6174747269627574652f6c6963656e7365)](//packagist.org/packages/bakabot/attribute) [![Build Status](https://camo.githubusercontent.com/f25c7a0c258c0bfcb996f9b68a90b2a66312f02612d8540485226b3751adb399/68747470733a2f2f7472617669732d63692e636f6d2f62616b61626f742d7068702f6174747269627574652e7376673f6272616e63683d6d61696e)](https://travis-ci.com/bakabot-php/attribute)
============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#bakabot-attribute---)

Provides accessors to single-value [PHP Attributes](https://www.php.net/manual/en/language.attributes.overview.php).

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

[](#installation)

`composer require bakabot/attribute`

Flavors
-------

[](#flavors)

For ease of use the library provides three identical way of accessing attribute values:

```
namespace Bakabot\Attribute;

// functions
attr(string|object $class, string $attribute, mixed $default = null): mixed;
getValue(string|object $class, string $attribute, mixed $default = null): mixed;

// public static method
AttributeValueGetter::getAttributeValue(string|object $class, string $attribute, mixed $default = null): mixed;
```

Usage
-----

[](#usage)

Works on both instances and class names:

```
use function Bakabot\Attribute\getValue;

#[Attribute]
class SomeAttribute
{
    public function __construct(private string $value) {}
}

#[SomeAttribute('foo')]
class MyClass {}

$value = getValue(MyClass::class, 'SomeAttribute'); // "foo"
$value = getValue(new MyClass(), 'SomeAttribute'); // "foo"
```

---

Throws a `MissingAttributeException` if the attribute is not set:

```
getValue(MyClass::class, 'UnknownAttribute');
// uncaught Bakabot\Attribute\Exception\MissingAttributeException
```

Unless you provide a default value as a third argument:

```
getValue(MyClass::class, 'UnknownAttribute', 'foo'); // "foo"
getValue(MyClass::class, 'UnknownAttribute', 'bar'); // "bar"
getValue(MyClass::class, 'UnknownAttribute', 'baz'); // "baz"
```

For heavy lifting or lazy evaluation, a default value can be any `callable`, in which case its resulting value will be cached.

```
getValue(MyClass::class, 'UnknownAttribute', fn () => 'bar'); // "bar"
getValue(MyClass::class, 'UnknownAttribute'); // still "bar"
```

---

If the attribute is repeatable, it'll return an array of that attribute's values:

```
use function Bakabot\Attribute\getValue;

#[Attribute(Attribute::IS_REPEATABLE)]
final class RepeatableAttribute
{
    public function __construct(private string $value) {}
}

#[RepeatableAttribute('foo')]
#[RepeatableAttribute('bar')]
class MyClass {}

$value = getValue(MyClass::class, 'RepeatableAttribute'); // ["foo", "bar"]
```

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance54

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity41

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

308d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/5f61d225a45bcac5359c16f3cdda3c106322831ebc50f6fb03d4b87ce207b911?d=identicon)[nayleen](/maintainers/nayleen)

---

Top Contributors

[![nayleen](https://avatars.githubusercontent.com/u/3086616?v=4)](https://github.com/nayleen "nayleen (3 commits)")

### Embed Badge

![Health badge](/badges/bakabot-attribute/health.svg)

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

PHPackages © 2026

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