yep / reflection
PHP class reflection enhancements
Installs: 75 739
Dependents: 5
Suggesters: 0
Security: 0
Stars: 3
Watchers: 2
Forks: 1
Open Issues: 1
Requires
- php: >=7
Requires (Dev)
- phpunit/phpunit: 4.*
README
PHP class reflection enhancements (For PHP7+)
Packagist
Reflection is available on Packagist.org, just add the dependency to your composer.json.
{ "require" : { "yep/reflection": "^2.0" } }
or run Composer command:
php composer.phar require yep/reflection
What do Yep/Reflection?
"Test subject" and example code
<?php class SomeClass { private $someProperty; protected function someMethod($someArgument) { return $someArgument; } public function getSomeProperty() { return $this->someProperty; } public function setSomeProperty($someProperty) { $this->someProperty = $someProperty; } } class SomeClass2 extends SomeClass { } $someClass = new SomeClass(); $reflection = \Yep\Reflection\ReflectionClass::from($class = $someClass);
You can simply call the protected or private method
<?php $someClass = new SomeClass(); echo $reflection->invokeMethod($method = 'someMethod', $arguments = ['foo']); // 'foo'
You can simply set value to the protected or private property
<?php $someClass = new SomeClass(); $reflection->setPropertyValue($property = 'someProperty', $value = 'foo'); echo $someClass->getSomeProperty(); // 'foo'
You can simply get value from the protected or private property
<?php $someClass = new SomeClass(); $someClass->setSomeProperty('foo'); echo $reflection->getPropertyValue($property = 'someProperty'); // 'foo';
Wanna access parent or parent's private property?
<?php $someClass = new SomeClass2(); $someClass->setSomeProperty('foo'); echo $reflection->getParent()->getPropertyValue($property = 'someProperty'); // 'foo';