FSi Reflection Component is an extension of built-in reflection classes in PHP 5.3 that saves a lot memory, thanks to factory design pattern.
FSi Reflection component is an extension of built-in reflection classes in PHP 5.3. Some of their methods are rewritten in such way that reflection objects are cached and never created twice for the same class/method/property/function or extension. This is achieved by usage of factory pattern. Some of the methods that cannot be rewriten to use such a cache throw an exception. All ReflectionProperty and ReflectionMethod objects returned from this library are previously set as accessible so they can be used even if they're private or protected., (*1)
We highly recommend to use autoloader generated by composer.phar, (*2)
Adding reflection into composer.json, (*3)
{ ... "require": { ... "fsi/reflection": "0.9.*" ... }, ... }
The key idea of using this reflection library is not to contruct reflection classes by their constructors but through the factory() methods added to each reflection class. Let's assume we have a class named ClassA:, (*4)
``` php <?php class ClassA { private $privateProperty;, (*5)
protected $protectedProperty; public $publicProperty; public function __construct($constructorParam) { } private function privateMethod($paramA, $paramB) { return $paramA . '-' .$paramB; } protected function protectedMethod($paramC, $paramD) { return $paramC . '+' .$paramD; } public function publicMethod($paramE, $paramF) { return $paramE . '=' .$paramF; }
}, (*6)
In order to create reflection objects you can: ``` php <?php use FSi\Reflection\ReflectionClass; use FSi\Reflection\ReflectionProperty; use FSi\Reflection\ReflectionMethod; $reflectionClassA = ReflectionClass::factory('ClassA'); $reflectionPropertyPrivate = $reflectionClassA->getProperty('privateProperty'); $reflectionPropertyPrivate = ReflectionProperty::factory('ClassA', 'privateProperty'); $reflectionMethodPrivate = $reflectionClassA->getMethod('privateMethod'); $reflectionMethodPrivate = ReflectionMethod::factory('ClassA', 'privateMethod');
You must remember that using any reflection class' constructor directly in your code will throw an exception., (*7)