POPSuL / BetterReflection

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better Reflection

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.

Installation

Simply require using composer:

$ composer require roave/better-reflection

Usage

use Roave\BetterReflection\Reflection\ReflectionClass;

$classInfo = ReflectionClass::createFromName('Foo\Bar\MyClass');

Changes in BR 2.0

  • Changed instantiation of FindReflectionOnLine utility from new FindReflectionOnLine() to FindReflectionOnLine::buildDefaultFinder(). FindReflectionOnLine constructor now requires a SourceLocator parameter.
  • Minimum PHP 7.1
  • NotAString exception class is now gone
  • Identifier class requires string for $name parameter
  • CompilerContext requires second parameter (no longer optional, but still nullable)
  • Reflector now requires a string for $identiferName parameter
  • Namespace moved to \Roave\BetterReflection instead of just \BetterReflection

More documentation

Limitations

  • PHP cannot autoload functions, therefore we cannot statically reflect functions
  • Using ReflectionClass::createFromName() makes some assumptions. Alternative reflection techniques are possible to overcome this.

Authors

License

This package is released under the MIT license.

Contributing

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

About

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

License:MIT License


Languages

Language:PHP 99.9%Language:Shell 0.1%