PHPackages                             ryanve/traits - 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. ryanve/traits

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

ryanve/traits
=============

PHP traits for making extensible classes.

0.9.0(12y ago)518MITPHPPHP &gt;=5.4

Since Apr 3Pushed 12y ago1 watchersCompare

[ Source](https://github.com/ryanve/traits)[ Packagist](https://packagist.org/packages/ryanve/traits)[ Docs](https://github.com/ryanve/traits)[ RSS](/packages/ryanve-traits/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (11)Used By (0)

[traits](../../) ([0.9](../../releases))
========================================

[](#traits-09)

#### opensource [PHP traits](http://php.net/manual/en/language.oop5.traits.php)

[](#opensource-php-traits)

- [`Data`](Data.php) includes data/removeData methods.
- [`Emitter`](Emitter.php) is an event emitter based on [EventEmitter](http://nodejs.org/api/events.html).
- [`Mixin`](Mixin.php) is for making extensible [classes](http://php.net/manual/en/language.oop5.php).
- [`Aware`](Aware.php) includes instantiation and context helpers.

Usage
-----

[](#usage)

### Import into a class

[](#import-into-a-class)

```
class Example {
  use \traits\Mixin;
}
```

### Static mixins

[](#static-mixins)

#### static key/value mixin

[](#static-keyvalue-mixin)

```
Example::mixin('foo', function() {
  return 'bar';
});
```

#### static array mixin

[](#static-array-mixin)

```
Example::mixin([
  'foo' => function() {
    return 'bar';
  }
]);
```

#### static method call

[](#static-method-call)

```
Example::foo(); # 'bar'
```

### Instance mixins

[](#instance-mixins)

Specify instance methods by passing `true`

#### static key/value mixin

[](#static-keyvalue-mixin-1)

```
Example::mixin('foo', function() {
  return 'bar';
}, true);
```

#### instance array mixin

[](#instance-array-mixin)

```
Example::mixin([
  'foo' => function() {
    return 'bar';
  }
], true);
```

#### instance method call

[](#instance-method-call)

```
$example = new Example;
Example->foo(); # 'bar'
```

License
-------

[](#license)

[MIT](http://opensource.org/licenses/MIT)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

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

Total

10

Last Release

4504d ago

### Community

Maintainers

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

---

Top Contributors

[![ryanve](https://avatars.githubusercontent.com/u/949985?v=4)](https://github.com/ryanve "ryanve (29 commits)")

---

Tags

phpphp-traitsutilitytraitextensionOOPmixin

### Embed Badge

![Health badge](/badges/ryanve-traits/health.svg)

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

###  Alternatives

[bocharsky-bw/arrayzy

A native PHP arrays easy manipulation library in OOP way.

38425.4k](/packages/bocharsky-bw-arrayzy)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

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