Skip to content

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

License

Notifications You must be signed in to change notification settings

Roave/BetterReflection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

9a39c1f · Jan 6, 2025
Dec 30, 2024
Dec 6, 2021
Jun 22, 2023
Jan 6, 2025
Dec 30, 2024
Jan 5, 2025
Nov 30, 2021
Sep 4, 2024
Mar 10, 2024
Feb 14, 2018
Jan 2, 2017
Feb 4, 2023
Dec 6, 2021
Dec 30, 2024
Jan 1, 2025
Mar 11, 2024
Mar 12, 2024
Apr 21, 2024
Dec 2, 2024
Mar 12, 2024
Dec 30, 2024
Feb 3, 2023
Oct 31, 2022

Repository files navigation

Better Reflection

Mutation testing badge Type 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
  • 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.

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages