- What is goaop/parser-reflection used for in Laravel projects?
- It provides an AST-based reflection API that lets you inspect classes, methods, properties, and attributes directly from PHP source code without loading or executing those classes. In Laravel projects it is useful for static analyzers, code generators, documentation tools, IDE integrations, attribute validation, macro analysis, and deprecation checks. It is built on nikic/php-parser and is designed to be compatible with PHP's native Reflection classes.
- How do I install goaop/parser-reflection in a Laravel application?
- Install it with Composer using composer require goaop/parser-reflection. It is a standalone library rather than a Laravel service provider, so you typically use it inside custom commands, CI tooling, or analyzer code. The README notes that optional initialization can be performed before first use.
- Does goaop/parser-reflection work with Laravel 10 and newer?
- The package aligns well with Laravel 10 and newer because its modern PHP requirement matches the PHP versions used by current Laravel releases. The technical evaluation notes that the PHP 8.2+ mandate makes it a blocker for legacy Laravel 9.x applications. Check your app's PHP and package constraints before adopting it.
- Can goaop/parser-reflection analyze code without autoloading or executing classes?
- Yes. It parses PHP source files into an Abstract Syntax Tree and extracts reflection data from the syntax itself, so there is no include, require, or autoloading step. This avoids triggering constructors, static initializers, and other side effects during introspection.
- Is goaop/parser-reflection compatible with PHP's native Reflection API?
- Yes. The library is designed as a drop-in-compatible layer that extends native classes such as ReflectionClass and ReflectionMethod. That makes it easier to swap into tools that already expect PHP Reflection-style APIs while working from source code instead of loaded classes.
- Does it support PHP 8 attributes such as Laravel's #[Route] and #[Middleware]?
- Yes. The package includes PHP 8+ attribute support and an attribute-first design, which is important for modern Laravel routing, middleware, and custom attributes. You should still validate parsing against your own #[Route], #[Middleware], and custom attribute usage in CI.
- What PHP version does goaop/parser-reflection require?
- The technical evaluation states PHP 8.2+ as a hard requirement, while the README badge currently shows PHP >= 8.4. Because release constraints can differ, check the composer.json of the specific version you install. This requirement is why legacy Laravel 9.x projects are not a good fit.
- How does goaop/parser-reflection compare with PHPStan or nikic/php-parser?
- It is built on nikic/php-parser but provides a higher-level Reflection-compatible API for introspecting classes, methods, properties, and attributes. PHPStan focuses on static analysis rules and type checking, so parser-reflection is better viewed as complementary infrastructure for analyzers and tooling. For runtime edge cases, combining it with PHPStan is a practical approach.
- Can it analyze Laravel macros, fluent chains, and dynamic method calls?
- The AST-preserving architecture reduces false positives for Laravel's dynamic patterns such as __call and __getStatic, and newer syntax support improves analysis of fluent chains and macros. However, runtime-generated proxies and some highly dynamic framework behavior may still require hybrid static and runtime analysis.
- What limitations should I test for before using parser-reflection in production?
- Watch for dynamic proxies that may need hybrid analysis, false positives or false negatives around complex expressions, and AST parsing overhead on large codebases. Benchmark against a repository such as laravel/framework and tune ignore rules where appropriate. Test complex default values and attribute-heavy code in CI before relying on it for production tooling.