Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Better Reflection Laravel Package

roave/better-reflection

Enhanced PHP reflection for static analysis: reflect classes without loading them, from PHP code strings or closures, extract AST from functions/methods, and read type declarations and docblocks. Feature-rich but slower than native reflection.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Static Analysis Tools: Enables building advanced IDE plugins, linters, or code quality tools (e.g., PHPStan, Psalm) by providing deeper reflection capabilities than PHP’s native API.
  • Code Generation: Facilitates generating boilerplate code, migrations, or documentation (e.g., API specs, OpenAPI) by inspecting classes/methods without runtime overhead.
  • Testing Frameworks: Powers mocking, test data generation, or assertion libraries (e.g., Pest, PHPUnit) by reflecting unloaded classes or closures.
  • Build vs. Buy: Buy for static analysis needs; build only if requiring runtime reflection (native PHP Reflection is faster).
  • Roadmap Priorities:
    • Short-term: Integrate into existing static analysis tools to replace manual parsing (e.g., regex, tokenizers).
    • Long-term: Extend to support PHP 8.2+ features (e.g., attributes, enums) or build a custom IDE plugin.
  • Use Cases:
    • Debugging: Inspect closures or unloaded classes in error logs.
    • Security: Scan for deprecated methods or unsafe type hints.
    • Performance: Profile code by analyzing method signatures/AST without execution.

When to Consider This Package

Adopt if:

  • You need static analysis (e.g., type checking, code metrics) beyond PHP’s native reflection.
  • Your tool requires reflecting unloaded classes, closures, or AST extraction (e.g., for rewriting code).
  • You’re building a PHP-specific tool (e.g., IDE, linter) and want to avoid reinventing reflection logic.

Avoid if:

  • You need runtime reflection (use PHP’s native ReflectionClass for speed).
  • Your use case is simple (e.g., checking if a class exists or calling methods dynamically).
  • You’re working with functions (BetterReflection cannot statically reflect them; use ReflectionFunction for runtime).
  • You require full compatibility with ReflectionExtension or ReflectionZendExtension (unsupported).

Alternatives:

  • PHPStan/Psalm: Use their built-in reflection if you’re already using them.
  • Nikic/PhpParser: For AST manipulation without reflection overhead.
  • Native Reflection: If performance is critical and features suffice.

How to Pitch It (Stakeholders)

For Executives: *"BetterReflection lets us build smarter, faster static analysis tools—like a supercharged X-ray for PHP code. Instead of guessing what classes/methods do, we can inspect them before they run, enabling:

  • Fewer bugs (catch type errors early via advanced reflection).
  • Faster development (auto-generate docs, tests, or migrations).
  • Competitive edge (e.g., custom IDE plugins or security scanners). It’s a drop-in replacement for native reflection where static analysis is needed, with no runtime cost. The trade-off? A tiny performance hit for development tools—worth it for accuracy and speed in CI/CD."*

For Engineers: *"This is the Swiss Army knife for PHP static analysis. Key wins:

  • Reflect unloaded classes/closures: Debug or analyze code without loading it (e.g., closures in error logs).
  • AST access: Rewrite code or generate templates by parsing method/function bodies.
  • Type safety: Extract PHPDoc/type hints for tools like PHPStan or custom validators.
  • IDE/Plugin potential: Build features like ‘go to definition’ or ‘rename symbol’ for custom languages. Not for runtime: If you’re instantiating objects or calling methods dynamically, stick with native reflection. But for anything static—this is the way."*
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium
sandermuller/package-boost-laravel
sandermuller/boost-skills
redaxo/core
yusufgenc/filament-api-forge
l3aro/rating-star-for-filament
leek/filament-subtenant-scope
anil/file-picker
broqit/fields-ai