This package is abandoned and no longer maintained. The author suggests using the roave/better-reflection package instead.

Better Reflection - an improved code reflection API

v4.0.0 2018-04-01 22:30 UTC

This package is not auto-updated.

Last update: 2022-02-01 13:10:23 UTC


Build Status Build Status Scrutinizer Code Quality Code Coverage Latest Stable Version License

Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.

Why is it better?

  • 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
  • Fetch return type declaration and parameter type declarations in PHP 7 code (even when running PHP 5!)
  • Change or remove PHP 7 parameter type and return type declarations from methods and functions
  • Change the body of a function or method to do something different
  • Moar stuff coming soon!

Be sure to read more in the feature documentation.


Simply require using composer:

$ composer require rector/better-reflection



use Rector\BetterReflection\BetterReflection;

$classInfo = (new BetterReflection())



Please refer to the Upgrade Documentation documentation to see what is required to upgrade your installed BetterReflection version.


  • PHP cannot autoload functions, therefore we cannot statically reflect functions


This package is released under the MIT license.


If you wish to contribute to the project, please read the CONTRIBUTING notes.