PHPackages                             tourze/getter-setter-trait - 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. tourze/getter-setter-trait

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

tourze/getter-setter-trait
==========================

Getter/Setter Trait

1.0.0(6mo ago)113MITPHPPHP ^8.2CI passing

Since Apr 21Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/tourze/getter-setter-trait)[ Packagist](https://packagist.org/packages/tourze/getter-setter-trait)[ RSS](/packages/tourze-getter-setter-trait/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)Dependencies (4)Versions (4)Used By (0)

getter-setter-trait
===================

[](#getter-setter-trait)

[English](README.md) | [中文](README.zh-CN.md)

[![Latest Stable Version](https://camo.githubusercontent.com/39d13df39ecf7d854185fcf3182f548e85d4535848d3e88e02ffa44646c25360/68747470733a2f2f706f7365722e707567782e6f72672f746f75727a652f6765747465722d7365747465722d74726169742f762f737461626c65)](https://packagist.org/packages/tourze/getter-setter-trait)[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/cc9cdea9aa96b40a822425e981b0a030e3371202973c7d57b74e8e99834f81dc/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e312d626c7565)](https://www.php.net/)[![Coverage Status](https://camo.githubusercontent.com/43100e0080977796a2fb7d86f0123da8fdc9e89388b7dae3d2af9930d1eee2a4/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f746f75727a652f6765747465722d7365747465722d74726169742f62616467652e737667)](https://coveralls.io/github/tourze/getter-setter-trait)

A lightweight PHP library providing reusable Getter and Setter traits for object property access, inspired by Yii2 conventions. It enables magic property access (`__get`, `__set`) with robust exception handling for unknown or write/read-only properties.

Features
--------

[](#features)

- Simple integration of getter/setter magic methods via traits
- Yii2-style exception handling for property access
- Automatic detection of getter/setter methods
- Support for property existence checks
- Designed for PHP 8.1+

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

[](#installation)

Requires PHP 8.1 or higher.

Install via Composer:

```
composer require tourze/getter-setter-trait
```

Quick Start
-----------

[](#quick-start)

```
use Tourze\GetterSetterTrait\GetterTrait;
use Tourze\GetterSetterTrait\SetterTrait;
use Tourze\GetterSetterTrait\PropertyTrait;

class User
{
    use GetterTrait, SetterTrait, PropertyTrait;

    private string $name = '';

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

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

$user = new User();
$user->name = 'Tom';
echo $user->name; // Tom
```

Documentation
-------------

[](#documentation)

- **GetterTrait**: Implements `__get($name)` for magic property reading.
- **SetterTrait**: Implements `__set($name, $value)` for magic property writing.
- **PropertyTrait**: Provides `hasProperty`, `canGetProperty`, `canSetProperty` helpers.
- Throws `UnknownPropertyException` for undefined properties, `InvalidCallException` for read/write-only properties (compatible with Yii2).

### Advanced Usage

[](#advanced-usage)

- You may override getter/setter methods for custom logic.
- Use `PropertyTrait` to check property accessibility programmatically.

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

[](#contributing)

Contributions are welcome! Please follow these steps:

- Submit issues for bugs or feature requests.
- Fork the repository and create pull requests.
- Ensure code style and run tests before submitting.
- Follow [PSR-12](https://www.php-fig.org/psr/psr-12/) coding standards.

License
-------

[](#license)

This project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

Author
------

[](#author)

tourze Team

---

> This README is generated based on the actual codebase and follows the project documentation rules.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance71

Regular maintenance activity

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

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

Every ~96 days

Total

3

Last Release

192d ago

Major Versions

0.0.2 → 1.0.02025-10-31

PHP version history (2 changes)0.0.1PHP ^8.1

1.0.0PHP ^8.2

### Community

Maintainers

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

---

Top Contributors

[![tourze](https://avatars.githubusercontent.com/u/13899502?v=4)](https://github.com/tourze "tourze (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tourze-getter-setter-trait/health.svg)

```
[![Health](https://phpackages.com/badges/tourze-getter-setter-trait/health.svg)](https://phpackages.com/packages/tourze-getter-setter-trait)
```

###  Alternatives

[log1x/acf-composer

Create fields, blocks, option pages, and widgets using ACF Builder and Sage 10

493760.2k13](/packages/log1x-acf-composer)[markrogoyski/ipv4-subnet-calculator

Network calculator for subnet mask and other classless (CIDR) network information.

177813.7k6](/packages/markrogoyski-ipv4-subnet-calculator)[b13/menus

Easy and fast menus for TYPO3 Frontends

58534.7k1](/packages/b13-menus)[hfig/mapi

Pure PHP library for reading and manipulating Microsoft Outlook .msg messages (MAPI documents)

40420.9k2](/packages/hfig-mapi)

PHPackages © 2026

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