php-di/phpdoc-reader
PhpDocReader parses @var and @param docblock types to resolve class names, supporting fully qualified, imported, relative, and aliased names with the same rules as PHP. Primitive types are ignored; only valid class names are returned. Used by PHP-DI.
@param Backend $backend when the constructor has no native type hint. Whether we ship "works out of the box on legacy code" is a DX decision, and this package is the cheapest way to enable it.use-import, alias, and relative-namespace resolution ourselves — dozens of edge cases, a known source of bugs. This is a buy (or rather, free-dependency) decision.Adopt when:
@var / @param.Look elsewhere when:
nikic/php-parser, phpdocumentor/reflection-docblock, or PHPStan is already in our dependency graph — do not add a second parser for one narrow capability.null for @var string.For executives (one paragraph): This is a tiny, free, MIT-licensed utility that reads @param and @var docblocks and tells us what class a developer intended. It is the piece that lets our product "just work" on older, untyped PHP codebases instead of demanding customers modernize first — a meaningful expansion of who can adopt us, at effectively zero licensing cost and roughly a sprint of engineering saved. It is already proven inside PHP-DI 6, one of the most widely used PHP containers. The one caveat is that its last release was 2020, so we will vendor-pin it and keep a small internal fork path; that is a routine, low-cost mitigation, not a blocker.
For engineering (the practical summary): We get PHP-accurate class-name resolution — fully qualified, use-imported, namespace-relative, and aliased — for free, and we skip writing and testing that logic ourselves. Three integration rules: (1) wrap it behind our own small interface so we can swap in reflection-docblock or attributes later; (2) memoize results per ReflectionProperty / ReflectionParameter, since it is reflection-based and not cheap; (3) pair it with an attributes-first, docblock-fallback strategy so PHP 8+ code is handled natively. Expect it to return class names only — no primitives, no unions, no generics — so anything richer stays our responsibility. Pin the version, run it against our CI matrix, and treat upstream as dormant.
How can I help you explore Laravel packages today?