entire-studio / dynamic-accessors
Dynamic setters and getters. While it can be done, it doesn't mean you should do it.
Package info
github.com/entire-studio/dynamic-accessors
pkg:composer/entire-studio/dynamic-accessors
v1.9.1
2025-08-05 06:39 UTC
Requires
- php: >=8.2
Requires (Dev)
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Dynamic setters and getters. While it can be done, it doesn't mean you should do it.
Installation
Install the latest version with
$ composer require entire-studio/dynamic-accessors
Examples
Basic - accessors on class properties
<?php declare(strict_types=1); use EntireStudio\DynamicAccessors\{ DynamicAccessors, Get, Set }; /** * You can annotate your class for IDE completion * * @method string|void firstName(?string $argument = '') * @method void setLastName(string $name) * @method string getLastName() */ class Basic { use DynamicAccessors; #[Set, Get] private string $firstName; #[Set('setLastName'), Get('getLastName')] private string $lastName; } $basic = new Basic(); $basic->firstName('Clark'); $basic->setLastName('Kent'); printf( 'My name is %s %s.' . PHP_EOL, $basic->firstName(), $basic->getLastName(), );
$ php example/Basic.php
Constructor - accessors on constructor parameters
<?php declare(strict_types=1); use EntireStudio\DynamicAccessors\{ DynamicAccessors, Get, Set }; /** * You can annotate your class for IDE completion * * @method string|void firstName(?string $argument = '') * @method void setLastName(string $name) * @method string getLastName() */ class ConstructorPropertyPromotion { use DynamicAccessors; public function __construct( #[Set, Get] private string $firstName, #[Set('setLastName'), Get('getLastName')] private string $lastName, ) { } } $cpp = new ConstructorPropertyPromotion( 'Lois', 'Lane' ); printf( 'My name is %s %s.' . PHP_EOL, $cpp->firstName(), $cpp->getLastName(), );
$ php example/ConstructorPropertyPromotion.php
Commands
Development
composer test- runs test suite.composer sat- runs static analysis.composer style- checks codebase against PSR-12 coding style.composer style:fix- fixes basic coding style issues.