PHPackages                             wilmoore/attributes.php - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. wilmoore/attributes.php

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

wilmoore/attributes.php
=======================

minimal object attributes for PHP.

0.1.4(12y ago)222442MITPHPPHP &gt;=5.4.0

Since Jul 26Pushed 12y ago1 watchersCompare

[ Source](https://github.com/wilmoore/attributes.php)[ Packagist](https://packagist.org/packages/wilmoore/attributes.php)[ Docs](https://github.com/wilmoore/attributes.php)[ RSS](/packages/wilmoore-attributesphp/feed)WikiDiscussions master Synced yesterday

READMEChangelog (4)Dependencies (1)Versions (8)Used By (0)

Attributes Trait for PHP [![Build Status](https://camo.githubusercontent.com/5f38c837679572951a75d719a81c28ea9b78e7a6880b3033543f6618e1e2ee56/68747470733a2f2f7472617669732d63692e6f72672f77696c6d6f6f72652f617474726962757465732e7068702e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/wilmoore/attributes.php)
=============================================================================================================================================================================================================================================================================================================================

[](#attributes-trait-for-php-)

A minimal trait to decrease getter/setter boilerplate.

Features
--------

[](#features)

- Omit **setter/getter** methods until needed.
- JSON or Array representation of object attributes.
- Get values via `$object->firstName` or `$object->get('firstName')`
- Set values via `$object->firstName = 'My Name';` or `$object->set('firstName', 'My Name')`
- `isset`, `empty`, and `unset` work as expected.
- Define *acceptable* input values like `'seconds' => ['accepts' => '0..59']`
- Define *default* values like `'score' => ['default' => 0]`

Anti-Features
-------------

[](#anti-features)

- Leaning on [complex IDEs](http://goo.gl/tUh9j) to produce setter/getter cruft is not a good solution to the underlying problem.
- Leaning on an [ORM](http://www.doctrine-project.org/blog/a-doctrine-orm-odm-base-class.html#last-words) is not a good solution since not every object in your domain needs to be persisted.
- Leaning on [reflection-based meta-programming](http://php.net/reflectionclass.getdefaultproperties).

Examples
--------

[](#examples)

```
class Game {
  use Attributes;

  protected $__attributes = [
    'gameName'  => [],
    'userName'  => [],
    'score'     => ['accepts' => '0..100']
  ];
}

$game = new Game;
$game->set([
  'gameName' => 'pacman',
  'userName' => 'manny.pacquiao',
  'score'    => 95
]);

assert(95 === $game->score);

```

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

[](#installation)

### Composer

[](#composer)

```
"require": {
    "wilmoore/attributes.php": "*"
}

```

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

[](#requirements)

- PHP 5.4+
- \[optional\] PHPUnit 3.6+ to execute the test suite (phpunit --version)

Resources
---------

[](#resources)

- [Issues](https://github.com/metaphp/attributes/issues)
- [Contributors](https://github.com/metaphp/attributes/contributors)
- [Contributor Guide](https://github.com/wilmoore/attributes.php/wiki/Contributor-Guide)
- [Request for Comments: Property Accessors](https://wiki.php.net/rfc/propertygetsetsyntax-as-implemented)

Changelog
---------

[](#changelog)

- (0.0.2) 20120726: Added Travis Integration.
- (0.0.1) 20120726: Initial Usable Release.

LICENSE
-------

[](#license)

MIT

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 94.6% 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 ~102 days

Recently: every ~12 days

Total

7

Last Release

4475d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/51953?v=4)[Wil (₩) Moore III](/maintainers/wilmoore)[@wilmoore](https://github.com/wilmoore)

---

Top Contributors

[![wilmoore](https://avatars.githubusercontent.com/u/51953?v=4)](https://github.com/wilmoore "wilmoore (70 commits)")[![telkins](https://avatars.githubusercontent.com/u/53731?v=4)](https://github.com/telkins "telkins (4 commits)")

---

Tags

jsonvalidationeventsserializationattributespropertiesaccessormutatordefaultschangetracking

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/wilmoore-attributesphp/health.svg)

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

###  Alternatives

[opis/json-schema

Json Schema Validator for PHP

65141.2M263](/packages/opis-json-schema)[laravel-lang/attributes

Translation of form element names

274.3M11](/packages/laravel-lang-attributes)[evaisse/php-json-schema-generator

A JSON Schema Generator.

18310.5k1](/packages/evaisse-php-json-schema-generator)[fab2s/dt0

Immutable DTOs with bidirectional casting. No framework required. 8x faster than the alternative.

101.9k1](/packages/fab2s-dt0)

PHPackages © 2026

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