PHPackages                             maxalmonte14/magicproperties - 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. maxalmonte14/magicproperties

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

maxalmonte14/magicproperties
============================

A little but powerful package that allows you call getters and setters implicitly in PHP.

v2.0(7y ago)1317MITPHP ^7.0

Since Oct 24Compare

[ Source](https://github.com/maxalmonte14/magicproperties)[ Packagist](https://packagist.org/packages/maxalmonte14/magicproperties)[ RSS](/packages/maxalmonte14-magicproperties/feed)WikiDiscussions Synced 2w ago

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

About MagicProperties
---------------------

[](#about-magicproperties)

[![StyleCI](https://camo.githubusercontent.com/089c7e9ea0a10e67334bcea25963fea4a866bf0e66d9f3ade689c30d47171a86/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3130383134303335302f736869656c643f6272616e63683d646576656c6f70)](https://github.styleci.io/repos/108140350)[![Build Status](https://camo.githubusercontent.com/f04c01bbaa35f1ebc1399062b364d7120aa2b2e5b6988871368a0a408f4ed8c8/68747470733a2f2f7472617669732d63692e6f72672f6d6178616c6d6f6e746531342f6d6167696370726f706572746965732e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/maxalmonte14/magicproperties)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/1ab8e41a53555ef3e3db59c605041503238e41acca7b55d5267654f4ec1cc05c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6178616c6d6f6e746531342f6d6167696370726f706572746965732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/maxalmonte14/magicproperties/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/d0f917f3553c95e02bc53e84c936e1bdd793f1c52b6b7f4a676faa91e57de970/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6178616c6d6f6e746531342f6d6167696370726f706572746965732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/maxalmonte14/magicproperties/?branch=master)[![Build Status](https://camo.githubusercontent.com/b3af3ff19fe92d6a8c66b18b7e250b8d7ad2290e58cd627cc1d77b98d3362edb/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6178616c6d6f6e746531342f6d6167696370726f706572746965732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/maxalmonte14/magicproperties/build-status/master)

MagicProperties is a little but powerful package that allows you call getters and setters implicitly in all objects you want, something like C# properties or Laravel accessors and mutators (for Eloquent ORM).

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

[](#requirements)

```
PHP >= 7.0

```

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

[](#installation)

```
composer require "maxalmonte14/magicproperties"

```

Examples
--------

[](#examples)

Let's begin! with MagicProperties you can access to your getters and setters in a transparent way without exposing your business logic. First, use the traits in your class.

```
use MagicProperties\AutoAccessorTrait, AutoMutatorTrait;

class User {
    use AutoAccessorTrait, AutoMutatorTrait;

    private $username;
    private $token;
}
```

> **Note**: The AutoAccessorTrait and AutoMutatorTrait use the \_\_get and \_\_set PHP magic methods, if you're using it in your class you gonna receive some error for sure, so don't do that!

Step two define your gettables and settables in the constructor.

```
public function __construct()
{
    $this->gettables = ['username'];
    $this->settables = ['username'];
}
```

Step three, define your own getters and setters for your gettables and settables.

```
public function getUsername()
{
    return strtolower($this->username);
}

public function setUsername($newUsername)
{
    $this->username = strtoupper($newUsername);
}
```

> **Note**: You have to define your getters and setters following the convention "get + property name" and "set + property name", otherwise the property it's gonna set or get without calling any method. You can name your methods either camel case or snake case, anyway, it's gonna work!

The final step, enjoy calling your properties!

```
$user = new User();
$user->username = 'MaxAlmonte14'; // The value is set to MAXALMONTE14
echo $user->username; // Returns maxalmonte14
```

> **Note**: Take care about this, the package doesn't make available all your private properties to the public context, only the properties defined in the gettables and settables array are gonna be accessible, so, if you try to access to a private non-gettable/settable property an exception is gonna be thrown.

```
echo $user->token; // An InvalidPropertyCallException is thrown!
```

---

Since version 2.0 your getters are called automatic even if you don't register your properties in the `gettables` array. The following example should work as expected.

```
public function __construct()
{
    $this->settables = ['username'];
}

public function getUsername()
{
    return strtolower($this->username);
}

public function setUsername($newUsername)
{
    $this->username = strtoupper($newUsername);
}
```

```
$user = new User();
$user->username = 'MaxAlmonte14'; // The value is set to MAXALMONTE14
echo $user->username; // Returns maxalmonte14
```

The `gettables` array is still available for compatibility reasons, however could be removed in future versions.

###  Health Score

28

—

LowBetter than 51% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity62

Established project with proven stability

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

Total

4

Last Release

2831d ago

Major Versions

v1.1.1 → v2.02018-11-13

PHP version history (2 changes)v1.1.0PHP ^5.4 || ^7.0

v2.0PHP ^7.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12385704?v=4)[Max](/maintainers/maxalmonte14)[@maxalmonte14](https://github.com/maxalmonte14)

---

Tags

traitpropertiesaccessormutatorgettersettermagicproperties

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/maxalmonte14-magicproperties/health.svg)

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

###  Alternatives

[usmanhalalit/get-set-go

Dynamic Setter-Getter for PHP 5.4+

1913.8k1](/packages/usmanhalalit-get-set-go)[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)
