felixdorn / property-accessor
Read an unaccessible property with a nice helper
1.0.1
2021-05-16 09:13 UTC
Requires
- php: ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3
- pestphp/pest: ^0.3.8
- phpstan/phpstan: ^0.12.48
- symfony/var-dumper: ^5.2.0
This package is auto-updated.
Last update: 2024-12-16 17:27:19 UTC
README
Installation
Requires PHP 8.0.0+
You can install the package via composer:
composer require felixdorn/property-accessor
Usage
use function \Felix\PropertyAccessor\access; class Book { protected string $name = 'Harry Potter'; protected int $isbn = 44081224; } $object = new Book(); access($object, 'isbn'); // returns 44081224 // Properties are injected based on the parameter name passed to the function. access($object, function ($isbn, $name) { return $isbn . ' - ' . $name; }); // returns '44081124 - Harry Potter' access($object, ['isbn', 'name']); // returns ['isbn' => 44081224, 'name' => 'Harry Potter']
Testing
composer test
Property Accessor was created by Félix Dorn under the MIT license.