Weave 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

Better Reflection is a PHP reflection API for static analysis: reflect on classes without loading them, parse classes from strings, inspect closures, and extract AST and type information. It prioritizes features over speed, so it is not intended for runtime use.

View on GitHub
Deep Wiki
Context7

Product Decisions This Supports

  • Build vs. buy for static-analysis tooling. BetterReflection is infrastructure, not a user-facing feature. It informs whether to build custom code-intelligence capabilities—architecture checks, Laravel-aware analyzers, code generators—or adopt existing tools such as PHPStan/Larastan, Rector, and IDE Helper. Build only when existing tools cannot express a high-value, Laravel-specific rule or workflow.
  • Developer-experience roadmap. Supports investment decisions in CI quality gates, pre-merge checks, upgrade impact analysis, automated documentation, code generation, and onboarding aids. It can inspect application and vendor code without loading classes, which is useful in Laravel projects where booting the full framework for analysis is slow or unsafe.
  • Architecture and standards enforcement. Enables custom rules for layer boundaries, controller/service/model conventions, forbidden dependencies, dead code, and package/plugin compatibility. PM can prioritize rules by defect history, onboarding pain, or upgrade risk.
  • Laravel-specific tooling use cases. Examples: generating IDE/helper metadata, analyzing route/controller contracts, scanning package/plugin code, extracting method ASTs for custom linting, finding the reflection at a source line for error reporting, and checking upgrade compatibility across vendor code.
  • Feature boundary decisions. Confirms this belongs in development/CI tooling, not runtime request handling. PM should not approve it as a production feature dependency unless a concrete offline/async tooling use case exists.
  • Make vs. integrate. Decide whether to wrap it in Artisan commands/CI jobs or use existing analyzer plugins; decide whether to fund an internal platform team to own static analysis versus funding licenses/subscriptions for commercial tools.
  • Platform-upgrade readiness (updated by 6.75.0). The package now installs on PHP 8.6 and is mutation-tested on PHP 8.5, so it is no longer a blocker in a PHP version-upgrade plan. PM can carry it in the upgrade risk register as low risk, but should still require a pinned version and a CI run on the target PHP version before committing to an upgrade date.

When to Consider This Package

Consider adoption when:

  • You need to inspect PHP classes, methods, properties, parameters, closures, docblocks, and type declarations without loading or executing the code.
  • You need AST extraction from methods/functions for custom static analysis, code generation, documentation, or refactoring tools.
  • You need to analyze Laravel app/vendor/plugin code in CI, especially when Composer autoloading or framework bootstrapping is too slow or inappropriate.
  • You are extending an existing static-analysis ecosystem and need a lower-level reflection engine rather than a complete analyzer.
  • Your roadmap includes PHP runtime upgrades; the 6.75.x line supports PHP 8.6 installation and has test coverage on 8.5, which reduces "tooling blocks the upgrade" risk.
  • You need accurate property-visibility reflection inside traits; 6.75.0 fixes ReflectionProperty::isReadable()/isWritable() for trait scope, so custom rules that classify trait properties by visibility can be trusted (add a regression test if you already built such rules).
  • The use case is developer tooling where runtime performance is not the constraint; results can be cached or precomputed.
  • You can accept MIT licensing and community maintenance, and you have engineering capacity to pin versions, test upgrades, and own the integration.

Look elsewhere when:

  • You need runtime reflection inside a request; PHP's native Reflection* API is faster and sufficient.
  • You need to instantiate reflected classes, invoke closures, or rely on complete native parity; BetterReflection has known gaps such as newInstance, closure invocation, and extension reflection.
  • You need out-of-the-box Laravel analysis; prefer Larastan/PHPStan, IDE Helper, Rector, or similar tools rather than building on a low-level library.
  • The team cannot maintain custom tooling, or the business case is only "nice to have" code insights without measurable pain.
  • You need functions autoloaded/reflected in all cases; the README notes PHP cannot autoload functions, so static function reflection has limits.
  • You need guaranteed vendor support/SLA; this is a community package, not a commercial platform. Note the maintenance profile visible in this release: three PRs, a single contributor, no issues closed—steady but thin, so avoid making it a single point of failure for critical gates.

How to Pitch It (Stakeholders)

For executives: BetterReflection is a low-cost, MIT-licensed building block for developer productivity and risk reduction. It lets our tooling inspect PHP and Laravel code without booting the app, enabling safer upgrades, architecture enforcement, automated documentation, and CI quality checks. The 6.75.0 release is routine maintenance: PHP 8.6 install support, added test coverage on PHP 8.5, and a correctness fix for property visibility on traits. It is not a runtime dependency and not a product feature by itself; approve it only against a concrete tooling roadmap and pilot, and measure impact through CI defect detection, upgrade lead time, and onboarding time.

For engineering: It is a static-analysis reflection engine with AST and type information, useful for custom analyzers, code generators, and Laravel-aware tooling. Use it in CI/dev tooling, not in request paths. Prefer existing tools like PHPStan/Larastan first; build on BetterReflection only for differentiated rules or workflows. 6.75.0 is a non-breaking minor: it widens the PHP constraint to 8.6, adds mutation testing on 8.5, and fixes ReflectionProperty::isReadable()/isWritable() for trait scope—re-run any visibility/architecture rules that inspect trait properties and add a regression case. Wrap it behind our own interfaces, cache results, pin versions, and plan upgrade testing. Known gaps include runtime instantiation and closure invocation, so design fallbacks to native reflection where needed.

Recommendation: Run a time-boxed spike on one high-value use case—for example, an architecture rule or Laravel code generator. If it beats buy/adopt alternatives on cost and differentiation, proceed with a small internal tooling investment; otherwise, stay with established analyzers. This release does not change the recommendation, but it does clear a PHP-upgrade dependency question, so schedule the routine version bump and re-run trait-property visibility tests as part of normal maintenance.

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.
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
elmogy/larafast
xeviant/laravel-paystack
gorilladash/laravel-website-sdk
martialbe/flysystem-oss
chondal/3312client
jeroen-g/flickr
opscale-co/nova-genbi
itsjustvita/laravel-retention
tequilarapido/trackit
gregsphotography/site-builder-filament
cabaoctavio/laravel-query-log