Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. PHP
  3. Better Reflection

Better Reflection

MITPHP6.72.0

A PHP reflection API that improves upon the native one with features like reflecting on unloaded classes and extracting ASTs.

GitHubGitHub
1.2k stars138 forks0 contributors

What is Better Reflection?

Better Reflection is a PHP library that provides an enhanced reflection API with more features than PHP's built-in reflection. It allows developers to inspect classes, functions, and closures without loading them, extract abstract syntax trees, and access detailed type information for static analysis purposes.

Target Audience

PHP developers building static analysis tools, code generators, IDE plugins, or any tool requiring deep introspection of PHP code without execution.

Value Proposition

Developers choose Better Reflection over the native PHP reflection API because it offers advanced capabilities like reflecting on unloaded classes, analyzing code from strings, and extracting ASTs, which are essential for static analysis and development tooling.

Overview

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

Use Cases

Best For

  • Building static analysis tools for PHP codebases
  • Developing IDE plugins that require deep code introspection
  • Creating code generation or scaffolding utilities
  • Analyzing PHP code without loading classes into memory
  • Extracting and manipulating abstract syntax trees from PHP methods
  • Inspecting closures and their structure programmatically

Not Ideal For

  • Runtime applications where reflection performance is critical and native PHP reflection suffices
  • Projects focused exclusively on function analysis without class introspection
  • Simple development tasks that only require basic class metadata and can use built-in reflection

Pros & Cons

Pros

Unloaded Class Reflection

Allows analysis of classes without loading them into memory, essential for static analysis tools that inspect codebases without execution.

AST Extraction

Provides access to abstract syntax trees from methods, functions, and closures, enabling deep code inspection and manipulation for tooling.

Enhanced Type Information

Fetches detailed type declarations including PHP 7+ features, improving the accuracy of static analysis and code generation.

Closure and String Parsing

Can reflect on closures and parse classes directly from PHP code strings, offering flexibility for various analysis scenarios.

Cons

Performance Overhead

Significantly slower than PHP's native reflection API, making it impractical for performance-sensitive runtime applications, as admitted in the README.

Limited Function Support

Cannot statically reflect on functions due to PHP's autoloading limitations, restricting its use in function-centric analysis tools, as noted in the limitations section.

Complex Setup for Beginners

Requires familiarity with advanced reflection concepts and ASTs, which may pose a steep learning curve for developers new to static analysis, despite detailed documentation.

Frequently Asked Questions

Quick Stats

Stars1,247
Forks138
Contributors0
Open Issues15
Last commit3 days ago
CreatedSince 2015

Tags

#hacktoberfest#type-inspection#php-library#php#development-tools#reflection#code-analysis#ast#static-analysis

Built With

P
PHP

Included in

PHP32.5k
Auto-fetched 11 hours ago

Related Projects

PHP ParserPHP Parser

A PHP parser written in PHP

Stars17,465
Forks1,134
Last commit2 days ago
RectorRector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code

Stars10,417
Forks744
Last commit1 day ago
GrumPHPGrumPHP

A PHP code-quality tool

Stars4,313
Forks449
Last commit28 days ago
PhpactorPhpactor

Mainly a PHP Language Server with more features than you can shake a stick at

Stars1,924
Forks163
Last commit13 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub