Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.
- You can reflect on classes that are not already loaded, without loading them
- Ability to reflect on classes directly from a string of PHP code
- Better Reflection analyses the DocBlocks (using phpdocumentor/type-resolver)
- Reflecting directly on closures
- Ability to extract AST from methods and functions
- Ability to return AST representation of a class or function
- Moar stuff coming soon!
Be sure to read more in the feature documentation.
Simply require using composer:
$ composer require roave/better-reflection
Please note that the current version has unstable dependencies.
In order to install those dependencies, you can set "minimum-stability"
in
your composer.json
, and recommend that you set "prefer-stable"
:
{
"minimum-stability": "dev",
"prefer-stable": true
}
use BetterReflection\Reflector\ReflectionClass;
$classInfo = ReflectionClass::createFromName('Foo\Bar\MyClass');
- Compatibility with core Reflection API
- Basic usage instructions
- Using types
- The features
- Test suite
- AST extraction
- PHP cannot autoload functions, therefore we cannot statically reflect functions
- Using
ReflectionClass::createFromName()
makes some assumptions. Alternative reflection techniques are possible to overcome this.
This package is released under the MIT license.
If you wish to contribute to the project, please read the CONTRIBUTING notes.