PHPackages                             mfonte/propaccessor - 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. mfonte/propaccessor

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

mfonte/propaccessor
===================

A PHP Trait that adds support for direct access to object properties, with explicit accessors and mutators.

v1.0(2y ago)09GPL-3.0-or-laterPHPPHP &gt;=7.4

Since May 22Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mauriziofonte/propaccessor)[ Packagist](https://packagist.org/packages/mfonte/propaccessor)[ Docs](https://github.com/mauriziofonte/propaccessor)[ RSS](/packages/mfonte-propaccessor/feed)WikiDiscussions main Synced today

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

PHP PropAccessor
================

[](#php-propaccessor)

A PHP Trait that allows direct access to object properties via magic methods, mapping them to explicit accessor and mutator methods.

This package is a fork of [Propifier](https://github.com/BapCat/Propifier), updated for PHP 7.4 compatibility and extended functionality. Original license (GNU GPL v3) has been retained. Credits to the original author.

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

[](#installation)

Install via Composer:

```
composer require mfonte/propaccessor
```

Why Use This Package?
---------------------

[](#why-use-this-package)

In object-oriented programming, it's a common practice to use getter and setter methods to control access to an object's properties. However, this can lead to verbose code and reduce readability.

PHP PropAccessor allows you to:

- **Directly access properties** using `$object->property` syntax.
- **Maintain control** over property access through custom getter and setter methods.
- **Define array-like properties** that can be accessed using `$object->arrayProperty[$key]`.
- **Implement iterators** for properties, enabling `foreach` loops directly on object properties.

How Does It Work?
-----------------

[](#how-does-it-work)

By including the `PropifierTrait` in your class, the magic methods `__get()`, `__set()`, `__isset()`, and `__unset()` are implemented. These methods intercept property access and delegate to your defined getter, setter, and iterator methods based on naming conventions.

### Naming Conventions

[](#naming-conventions)

- **Getter Methods**: `getPropertyName()`, `isPropertyName()`, or `hasPropertyName()`
- **Setter Methods**: `setPropertyName()`
- **Iterator Methods**: `itrPropertyName()`

### Property Name Resolution

[](#property-name-resolution)

The property name is derived from your method names by removing the prefix (`get`, `set`, `is`, `has`, `itr`) and converting the remainder to camelCase or snake\_case, depending on your preference.

Examples
--------

[](#examples)

### Basic Usage

[](#basic-usage)

```
use Mfonte\PropAccessor\PropifierTrait;

class User {
    use PropifierTrait;

    private string $name;

    public function setName(string $name): void {
        $this->name = ucfirst($name);
    }

    public function getName(): string {
        return $this->name;
    }
}

$user = new User();
$user->name = 'john';
echo $user->name; // Outputs 'John'
```

### Boolean Properties

[](#boolean-properties)

```
class FeatureToggle {
    use PropifierTrait;

    private bool $isEnabled = false;

    public function isEnabled(): bool {
        return $this->isEnabled;
    }

    public function setEnabled(bool $value): void {
        $this->isEnabled = $value;
    }
}

$feature = new FeatureToggle();
$feature->enabled = true;

if ($feature->enabled) {
    // Feature is enabled
}
```

### Array Properties

[](#array-properties)

```
use ArrayIterator;

class Collection {
    use PropifierTrait;

    private array $items = [];

    public function setItems(int $index, mixed $value): void {
        $this->items[$index] = $value;
    }

    public function getItems(int $index): mixed {
        return $this->items[$index] ?? null;
    }

    public function itrItems(): ArrayIterator {
        return new ArrayIterator($this->items);
    }
}

$collection = new Collection();
$collection->items[0] = 'Item 1';
$collection->items[1] = 'Item 2';

foreach ($collection->items as $index => $item) {
    echo "$index: $item\n";
}
```

### Custom Property Mappings

[](#custom-property-mappings)

```
class Config {
    use PropifierTrait;

    protected static array $propertyMap = [
        'dbHost' => ['get' => 'getDatabaseHost', 'set' => 'setDatabaseHost'],
    ];

    private string $databaseHost;

    protected function getDatabaseHost(): string {
        return $this->databaseHost;
    }

    protected function setDatabaseHost(string $host): void {
        $this->databaseHost = $host;
    }
}

$config = new Config();
$config->dbHost = 'localhost';
echo $config->dbHost; // Outputs 'localhost'
```

Limitations and Notes
---------------------

[](#limitations-and-notes)

- **Virtual Properties**: The properties accessed are virtual and managed through magic methods.
- **Naming Conventions**: Method names must follow the defined naming conventions to be recognized.
- **No Automatic Type Conversion**: Ensure your getter and setter methods handle type conversions if necessary.
- **Custom Exceptions**: The package uses custom exceptions. Ensure they are included if you extract code snippets.

License
-------

[](#license)

This package is licensed under the GNU GPL v3. Credits to the original author of [Propifier](https://github.com/BapCat/Propifier).

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

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

771d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7733524e324e4a6f68d80bad3cfc5737cda0bfb072154210de09c7c2820d070c?d=identicon)[mauriziofonte](/maintainers/mauriziofonte)

---

Top Contributors

[![mauriziofonte](https://avatars.githubusercontent.com/u/1758841?v=4)](https://github.com/mauriziofonte "mauriziofonte (2 commits)")

---

Tags

setpropertypropertiesaccessormutatorgetgettersetter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mfonte-propaccessor/health.svg)

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

###  Alternatives

[antares/accessible-bundle

A bundle to easily use Accessible in Symfony projects.

153.8k](/packages/antares-accessible-bundle)[antares/accessible

PHP library that allows you to define your class' getters, setters and constructor with docblock annotations.

123.9k1](/packages/antares-accessible)

PHPackages © 2026

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