PHPackages                             ondrejmirtes/better-reflection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. ondrejmirtes/better-reflection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

ondrejmirtes/better-reflection
==============================

Better Reflection - an improved code reflection API

6.65.0.10(2mo ago)136.2M—2.6%7[1 PRs](https://github.com/ondrejmirtes/BetterReflection/pulls)4MITPHPPHP ^7.4 || ^8.0CI failing

Since Nov 2Pushed 1w ago3 watchersCompare

[ Source](https://github.com/ondrejmirtes/BetterReflection)[ Packagist](https://packagist.org/packages/ondrejmirtes/better-reflection)[ RSS](/packages/ondrejmirtes-better-reflection/feed)WikiDiscussions 6.70.x Synced 1mo ago

READMEChangelog (10)Dependencies (16)Versions (361)Used By (4)

Better Reflection
=================

[](#better-reflection)

[![Mutation testing badge](https://camo.githubusercontent.com/c3b15a5ebc7c96fa93ecef14aec5066470e8ca676568a91ac6d1e80a73402fb5/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f7374796c653d666c61742675726c3d687474707325334125324625324662616467652d6170692e737472796b65722d6d757461746f722e696f2532466769746875622e636f6d253246526f6176652532464265747465725265666c656374696f6e253246362e362e78)](https://dashboard.stryker-mutator.io/reports/github.com/Roave/BetterReflection/6.6.x)[![Type Coverage](https://camo.githubusercontent.com/e15549b52acc87b85c2e5af24fe4bcd28f46a4b44cbd34fa360cdbffa1475ab3/68747470733a2f2f73686570686572642e6465762f6769746875622f526f6176652f4265747465725265666c656374696f6e2f636f7665726167652e737667)](https://shepherd.dev/github/Roave/BetterReflection)[![Latest Stable Version](https://camo.githubusercontent.com/57516213d046e62937a551fbed02d6fc70201811ee9a0b646a1c6411323e5222/68747470733a2f2f706f7365722e707567782e6f72672f726f6176652f6265747465722d7265666c656374696f6e2f762f737461626c65)](https://packagist.org/packages/roave/better-reflection)[![License](https://camo.githubusercontent.com/236e392e8df270520a195f97f90776060ceb210d7f7574221b7d7ee187964656/68747470733a2f2f706f7365722e707567782e6f72672f726f6176652f6265747465722d7265666c656374696f6e2f6c6963656e7365)](https://packagist.org/packages/roave/better-reflection)

Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in [reflection API](https://php.net/manual/en/book.reflection.php).

Tip

Are you reflecting on how to improve your application? We offer consulting on this library, as well as plenty of other development work. If you need any help, feel free to [get in touch](https://roave.com/contact-us/).

\- The Roave Team

Why is it better?
-----------------

[](#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](docs/features.md).

Installation
------------

[](#installation)

Require using composer:

```
composer require roave/better-reflection
```

Usage
-----

[](#usage)

```
