roave / better-reflection
Better Reflection - an improved code reflection API
Installs: 8 645 810
Dependents: 134
Suggesters: 4
Security: 0
Stars: 1 196
Watchers: 29
Forks: 132
Open Issues: 15
Requires
- php: ~8.2.0 || ~8.3.2 || ~8.4.1
- ext-json: *
- jetbrains/phpstorm-stubs: 2024.3
- nikic/php-parser: ^5.3.1
Requires (Dev)
- phpbench/phpbench: ^1.3.1
- phpunit/phpunit: ^11.5.1
Suggests
- composer/composer: Required to use the ComposerSourceLocator
Conflicts
- thecodingmachine/safe: <1.1.3
- 6.50.x-dev
- 6.49.x-dev
- 6.49.0
- 6.48.x-dev
- 6.48.0
- 6.47.x-dev
- 6.47.0
- 6.46.x-dev
- 6.46.0
- 6.45.x-dev
- 6.45.0
- 6.44.x-dev
- 6.44.0
- 6.43.x-dev
- 6.43.0
- 6.42.x-dev
- 6.42.0
- 6.41.x-dev
- 6.41.0
- 6.40.x-dev
- 6.40.0
- 6.39.x-dev
- 6.39.0
- 6.38.x-dev
- 6.38.0
- 6.37.x-dev
- 6.37.0
- 6.36.x-dev
- 6.36.0
- 6.35.x-dev
- 6.35.0
- 6.34.x-dev
- 6.34.0
- 6.33.x-dev
- 6.33.0
- 6.32.x-dev
- 6.32.0
- 6.31.x-dev
- 6.31.0
- 6.30.x-dev
- 6.30.0
- 6.29.x-dev
- 6.29.0
- 6.28.x-dev
- 6.28.0
- 6.27.x-dev
- 6.27.0
- 6.26.x-dev
- 6.26.0
- 6.25.x-dev
- 6.25.0
- 6.24.x-dev
- 6.24.0
- 6.23.x-dev
- 6.23.0
- 6.22.x-dev
- 6.22.0
- 6.21.x-dev
- 6.21.0
- 6.20.x-dev
- 6.20.0
- 6.19.x-dev
- 6.19.0
- 6.18.x-dev
- 6.18.0
- 6.17.x-dev
- 6.17.0
- 6.16.x-dev
- 6.16.0
- 6.15.x-dev
- 6.15.0
- 6.14.x-dev
- 6.14.0
- 6.13.x-dev
- 6.13.0
- 6.12.x-dev
- 6.12.0
- 6.11.x-dev
- 6.11.0
- 6.10.x-dev
- 6.10.0
- 6.9.x-dev
- 6.9.0
- 6.8.x-dev
- 6.8.0
- 6.7.x-dev
- 6.7.0
- 6.6.x-dev
- 6.6.0
- 6.5.x-dev
- 6.5.0
- 6.4.x-dev
- 6.4.1
- 6.4.0
- 6.3.x-dev
- 6.3.0
- 6.2.x-dev
- 6.2.0
- 6.1.x-dev
- 6.1.0
- 6.0.x-dev
- 6.0.0
- 5.12.x-dev
- 5.11.x-dev
- 5.11.1
- 5.11.0
- 5.10.x-dev
- 5.10.0
- 5.9.x-dev
- 5.9.0
- 5.8.x-dev
- 5.8.0
- 5.7.x-dev
- 5.7.0
- 5.6.x-dev
- 5.6.0
- 5.5.x-dev
- 5.5.0
- 5.4.x-dev
- 5.4.0
- 5.3.x-dev
- 5.3.1
- 5.3.0
- 5.2.x-dev
- 5.2.0
- 5.1.x-dev
- 5.1.0
- 5.0.x-dev
- 5.0.7
- 5.0.6
- 5.0.5
- 5.0.4
- 5.0.3
- 5.0.2
- 5.0.1
- 5.0.0
- 4.12.x-dev
- 4.12.2
- 4.12.1
- 4.12.0
- 4.11.x-dev
- 4.11.0
- 4.10.x-dev
- 4.10.0
- 4.9.x-dev
- 4.9.0
- 4.8.x-dev
- 4.8.0
- 4.7.0
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.1
- 3.1.0
- 3.0.0
- 2.0.2
- 2.0.1
- 2.0.0
- 1.2.0
- 1.1.0
- 1.0.1
- 1.0.0
- 0.1.0
- dev-renovate/all-minor-patch
- dev-renovate/lock-file-maintenance
This package is auto-updated.
Last update: 2024-12-21 09:59:49 UTC
README
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
- 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
- Moar stuff coming soon!
Typically you would use Better Reflection for static analysis tooling. It can serve as a baseline to access type information (e.g. doc blocks, type declarations), method/function body AST fetching etc. for static analysis.
Better Reflection is NOT suited to runtime usage, since performance is much worse than PHP built-in reflection. If you do not want to do anything that native PHP reflection can't do, then just use native PHP reflection! The "Better" in Better Reflection refers to feature, not speed!
Be sure to read more in the feature documentation.
Installation
Require using composer:
composer require roave/better-reflection
Usage
<?php use Roave\BetterReflection\BetterReflection; $classInfo = (new BetterReflection()) ->reflector() ->reflectClass(\Foo\Bar\MyClass::class);
Documentation
Upgrading
Please refer to the Upgrade Documentation documentation to see what is required to upgrade your installed
BetterReflection
version.
Limitations
- PHP cannot autoload functions, therefore we cannot statically reflect functions
License
This package is released under the MIT license.
Contributing
If you wish to contribute to the project, please read the CONTRIBUTING notes.