PHPackages                             b2r/simple-accessor - 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. b2r/simple-accessor

ActiveLibrary

b2r/simple-accessor
===================

v0.1.0(9y ago)0991MITPHPPHP &gt;=7.0

Since Feb 3Pushed 9y ago1 watchersCompare

[ Source](https://github.com/b2r/php-simple-accessor)[ Packagist](https://packagist.org/packages/b2r/simple-accessor)[ Docs](https://github.com/b2r/php-simple-accessor)[ RSS](/packages/b2r-simple-accessor/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (1)Versions (2)Used By (1)

b2rPHP: SimpleAccessor
======================

[](#b2rphp-simpleaccessor)

Simple accessor trait

[![Build Status](https://camo.githubusercontent.com/3a07ba23973f1af9063c8687000e22a2ae40464dd1b8def8588b74383fb68f34/68747470733a2f2f7472617669732d63692e6f72672f6232722f7068702d73696d706c652d6163636573736f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/b2r/php-simple-accessor)

- [CHANGELOG](CHANGELOG.md)

Traits
------

[](#traits)

- Getter
- Setter
- Accessor: Getter + Setter

Basic Usage
-----------

[](#basic-usage)

```
use b2r\Component\SimpleAccessor\Accessor;

class Foo
{
    use Accessor;

    private $value = 0;

    public function getSquare()
    {
        return $this->value * $this->value;
    }

    public function setValue($value)
    {
        $this->value = (int)$value;
    }
}

$foo = new Foo();
$foo->value = '10'; // Invoke `setValue()`
var_dump($foo->value); #=>int(10)
var_dump($foo->square); #=>int(100) Invoke `getSquare()`

//$foo->undefined = 'Undefined'; #=> throw b2r\Component\Exception\InvalidPropertyException
```

Getter::getPropertyValue
------------------------

[](#gettergetpropertyvalue)

Getter core method

`protected function getPropertyValue($name, array $options = null)`

```
$options = [
    'default'  => null,    # Undefined property default value
    'prefixes' => ['get'], # Getter method prefixes
    'read'     => true,    # Read private/protected property?
    'strict'   => true,    # Thorw exception?
]
```

Setter::setPropertyValue
------------------------

[](#settersetpropertyvalue)

Setter core method

`protected function setPropertyValue($name, $value, array $options = null)`

```
$options = [
    'create'    => false,   # Create undefined property?
    'immutable' => false,   # Immutable?
    'prefixes'  => ['set'], # Setter method prefixes
    'update'    => false,   # Update private/protected property?
    'strict'    => true,    # Thorw exception?
]
```

More samples
------------

[](#more-samples)

### Loose

[](#loose)

Do not throw exception

```
use b2r\Component\SimpleAccessor\Accessor;

class Foo
{
    use Accessor;

    private $value = 0;

    public function __get($name)
    {
        return $this->getPropertyValue($name, [
            'strict'  => false,
            'default' => 'Default value for undefined property'
        ]);
    }
}

$foo = new Foo();
var_dump($foo->undefined); #=>"Default value for undefined property"
```

### Immutable

[](#immutable)

Immutable (write once)

```
use b2r\Component\SimpleAccessor\Accessor;

class Foo
{
    use Accessor;

    private $value = 0;

    public function __set($name, $value)
    {
        return $this->setPropertyValue($name, $value, ['immutable' => true]);
    }

    protected function setValue($value)
    {
        $this->value = (int)$value;
    }
}

$foo = new Foo();
$foo->value = '10'; # Invoke `setValue()`
var_dump($foo->value); #=>int(10)
$foo->value = 100; #=>b2r\Component\Exception\InvalidPropertyException: Invalid property Foo::$value is immutable
```

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

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

3384d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

accessorphp

### Embed Badge

![Health badge](/badges/b2r-simple-accessor/health.svg)

```
[![Health](https://phpackages.com/badges/b2r-simple-accessor/health.svg)](https://phpackages.com/packages/b2r-simple-accessor)
```

PHPackages © 2026

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