ivastly / php-reflection
PHP Reflection API simplified.
Installs: 6 019
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: 8.*
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-12-17 05:02:20 UTC
README
Rationale
Ever questioned yourself why you need to write more than a single line of code to get a value of private property? What if the property is private and defined in a parent class? Even more toil is required. Please welcome a library to solve this trouble once and for all.
Functionality
- Read value of any property of an object, including parent classes, with a single call.
- Find out the visibility of a property, including parent classes, with a single call.
- Check if a property exists in a class.
Installation
composer require ivastly/php-reflection
Usage
class ParentClass { private $property = 'parent private property'; } class C extends ParentClass { } $object = new C(); $reflection = new \Ivastly\PhpReflection\Reflection(); $value = $reflection->getProperty($object, 'property'); $visibility = $reflection->getVisibility($object, 'property'); echo "$visibility \$property = '$value;'\n"; // private $property = 'parent private property';
See example.php
Tests
make test
Code coverage 🟩
License
See LICENSE.md
Contributing
See CONTRIBUTING.md