PHPackages                             benrowe/properties - 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. benrowe/properties

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

benrowe/properties
==================

A simple runtime package for handling properties on a class

1.1.1(8y ago)15701MITPHPPHP ~7.1

Since Mar 22Pushed 8y ago1 watchersCompare

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

READMEChangelog (8)Dependencies (3)Versions (9)Used By (0)

Properties
==========

[](#properties)

[![Latest Version on Packagist](https://camo.githubusercontent.com/ef165a154ddf3103877c7d048c4e0c69daff25492eedb0e0832abdf4833b0f98/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62656e726f77652f70726f706572746965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/benrowe/properties)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/8c7e550dc1a6be3d877e31e344adfb4f662fd82d12e9f7db425479d130b018d0/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62656e726f77652f70726f706572746965732f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/benrowe/properties)[![Coverage Status](https://camo.githubusercontent.com/ccdbeb51a1b147db54fb9a96c2be1aa653c8060f9a443daca85bdcfdef1d1d2f/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f62656e726f77652f70726f706572746965732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/benrowe/properties/code-structure)[![Quality Score](https://camo.githubusercontent.com/0cc5286946798e1b2a860f14eca3d627458a41773f5dd798fafd1c49a93ee45a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62656e726f77652f70726f706572746965732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/benrowe/properties)[![Total Downloads](https://camo.githubusercontent.com/0d86436b532351f2e66863d8189873105a622a62c0481e1a2ca449bbcf1f0a72/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62656e726f77652f70726f706572746965732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/benrowe/properties)

Adds the ability to add properties to a class at runtime.

Install
-------

[](#install)

Via Composer

```
$ composer require benrowe/properties
```

Usage
-----

[](#usage)

```
class Sample extends AbstractBase
{
    public function __construct()
    {
        // do stuff
        $this->configureProperties();
        // properties now available
    }

    /**
     * This method is automatically called by AbstractBase once
     * the constructor has finished executing
     */
    public function configureProperties()
    {
        $this->
            addProperty('simple')

        $this
            ->addProperty('complex', 'string', 'default value')
            ->setter(function($value) {
                return trim($value);
            })
            ->getter(function($value) {
                return str_reverse($value);
            })
            ->validate(function ($value) {
                return strlen($value) > 0;
            });

    }
}

$sample = new Sample;
$sample->simple = 'test';
$sample->undefined = 'newval'; // throws PropertyException "Undefined property 'undefined'"
$sample->complex; // 'default value'
$sample->complex = ''; // throws PropertyException "property 'complex' invalid value on set"
$sample->complex = ' hello world';
echo $sample->complex; //'dlrow olleh';
```

Each property is defined programatically (at runtime), and requires the class to run this code (with a hook).

Each property can have a

- name:string
- data type(s): string
- validation: string|closure
- setter: closure
- getter:string
- default value (null): mixed
- value: mixed (depends on data type/validation/setter)

TODO
----

[](#todo)

- add the ability for a setter to reject a value by throwing an exception
- build custom validation support for setting the value
- instead of providing a closure for the setter, provide a laravel style validation string.
- add a helper function to restrict the setter to a list of known values `$this->addProperty('key')->isIn(['foo', 'bar']);`

Change log
----------

[](#change-log)

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

Testing
-------

[](#testing)

```
$ composer test
```

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ben Rowe](https://github.com/benrowe)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community21

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Recently: every ~9 days

Total

8

Last Release

2947d ago

Major Versions

0.1.2 → 1.0.02018-04-28

PHP version history (2 changes)0.1.0PHP ~7.0

1.0.0PHP ~7.1

### Community

Maintainers

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

---

Top Contributors

[![benrowe](https://avatars.githubusercontent.com/u/1509442?v=4)](https://github.com/benrowe "benrowe (63 commits)")[![philsturgeon](https://avatars.githubusercontent.com/u/67381?v=4)](https://github.com/philsturgeon "philsturgeon (32 commits)")[![frankdejonge](https://avatars.githubusercontent.com/u/534693?v=4)](https://github.com/frankdejonge "frankdejonge (19 commits)")[![RobLoach](https://avatars.githubusercontent.com/u/25086?v=4)](https://github.com/RobLoach "RobLoach (7 commits)")[![EmanueleMinotto](https://avatars.githubusercontent.com/u/417201?v=4)](https://github.com/EmanueleMinotto "EmanueleMinotto (5 commits)")[![bcrowe](https://avatars.githubusercontent.com/u/752603?v=4)](https://github.com/bcrowe "bcrowe (5 commits)")[![reinink](https://avatars.githubusercontent.com/u/882133?v=4)](https://github.com/reinink "reinink (5 commits)")[![colinodell](https://avatars.githubusercontent.com/u/202034?v=4)](https://github.com/colinodell "colinodell (5 commits)")[![marcqualie](https://avatars.githubusercontent.com/u/101022?v=4)](https://github.com/marcqualie "marcqualie (4 commits)")[![ravage84](https://avatars.githubusercontent.com/u/625761?v=4)](https://github.com/ravage84 "ravage84 (4 commits)")[![browner12](https://avatars.githubusercontent.com/u/5232313?v=4)](https://github.com/browner12 "browner12 (3 commits)")[![hassankhan](https://avatars.githubusercontent.com/u/1781985?v=4)](https://github.com/hassankhan "hassankhan (3 commits)")[![alexbilbie](https://avatars.githubusercontent.com/u/77991?v=4)](https://github.com/alexbilbie "alexbilbie (2 commits)")[![assertchris](https://avatars.githubusercontent.com/u/200609?v=4)](https://github.com/assertchris "assertchris (2 commits)")[![barryvdh](https://avatars.githubusercontent.com/u/973269?v=4)](https://github.com/barryvdh "barryvdh (2 commits)")[![kdubuc](https://avatars.githubusercontent.com/u/895661?v=4)](https://github.com/kdubuc "kdubuc (2 commits)")[![mAAdhaTTah](https://avatars.githubusercontent.com/u/4371429?v=4)](https://github.com/mAAdhaTTah "mAAdhaTTah (2 commits)")[![Jeroen-G](https://avatars.githubusercontent.com/u/1116853?v=4)](https://github.com/Jeroen-G "Jeroen-G (1 commits)")[![sanmai](https://avatars.githubusercontent.com/u/139488?v=4)](https://github.com/sanmai "sanmai (1 commits)")[![localheinz](https://avatars.githubusercontent.com/u/605483?v=4)](https://github.com/localheinz "localheinz (1 commits)")

---

Tags

composer-packagephpphp7commandpropertiesstrictstrict-typing

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/benrowe-properties/health.svg)

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

###  Alternatives

[kdyby/strict-objects

Simple trait to make your class strict, when calling or accessing undefined member (property or method).

311.7M18](/packages/kdyby-strict-objects)[consistence/consistence

Consistence - consistent approach and additions to PHP's functionality

1821.1M18](/packages/consistence-consistence)[strictus/strictus

Strict Typing for local variables in PHP

1627.4k](/packages/strictus-strictus)[selective/config

Config component, strictly typed

16191.9k3](/packages/selective-config)[skywarth/chaotic-schedule

Randomize scheduled command execution time and date intervals

12263.8k](/packages/skywarth-chaotic-schedule)[synolia/sylius-scheduler-command-plugin

Scheduler Command Plugin.

35389.6k](/packages/synolia-sylius-scheduler-command-plugin)

PHPackages © 2026

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