- How do I install symfony/type-info in a Laravel application?
- Install it with composer require symfony/type-info. If you need to resolve raw type strings from PHPDoc, also install phpstan/phpdoc-parser with composer require phpstan/phpdoc-parser. No Laravel service provider is required because the component is used directly through classes such as TypeResolver and Type. After installation, verify the installed PHP and Laravel versions against the package's Composer constraints.
- What can I use symfony/type-info for in Laravel?
- It is useful for runtime type resolution, reflection-based introspection, custom validators, middleware, serializers, OpenAPI or JSON:API schema generation, and testing utilities. You can resolve types from reflection targets or raw strings and then inspect, cast, or validate the resulting Type instance. In Laravel, this fits well when you need structured type information beyond native reflection.
- Which Laravel and PHP versions does symfony/type-info support?
- The package is a Symfony component and does not declare Laravel-specific integrations, so compatibility depends on its PHP and Symfony constraints. In a Laravel app, re-test against your installed Laravel and PHP versions before adoption. Also verify coexistence with symfony/property-info and your installed phpstan/phpdoc-parser major version.
- How do I resolve a type from a Laravel model property or a string?
- Create a resolver with TypeResolver::create() and pass it a ReflectionProperty, ReflectionParameter, or a type string. For example, resolve(new ReflectionProperty(User::class, 'id')) returns an int Type, while resolve('bool') returns a bool Type. You can then inspect the Type, cast it to string, or use it in validation and schema-generation logic.
- Is symfony/type-info stable enough for production Laravel use?
- Version 8.1.8 is a bugfix-only release with no breaking changes, new features, or deprecations, which lowers the immediate risk. Treat it as a stabilization upgrade over the beta line and run your existing test suite before broad adoption. Remaining production concerns include reflection overhead, cache design, malformed PHPDoc, and dependency constraint mismatches.
- How should I cache type resolution in Laravel?
- The package is stateless, so caching is your responsibility rather than a built-in feature. Cache resolved types at the class or property level and invalidate entries on deployment or when source files change. Implement or verify the cache layer before enabling per-request type resolution in middleware or validators.
- What was fixed in symfony/type-info v8.1.8?
- v8.1.8 fixes edge cases including infinite recursion on recursive type aliases, Type::union() with mixed, printing and resolving array or object shape keys containing quotes or backslashes, accepts() for union and intersection types, unknown class constants, class keyword constants without type context, and global namespace class names. It also improves quoted-string handling with phpstan/phpdoc-parser 1.x. No API migration is expected from this release.
- Does symfony/type-info work with phpstan/phpdoc-parser 1.x or 2.x?
- phpstan/phpdoc-parser is optional and only needed for resolving raw type strings; reflection-based resolution works without it. v8.1.8 includes a fix for quoted strings with phpstan/phpdoc-parser 1.x, which reduces compatibility risk. However, you should verify the actual installed major version against symfony/type-info's declared Composer constraints, especially if your app expects ^2.0.
- What are alternatives to symfony/type-info for PHP type introspection?
- Native PHP Reflection covers many runtime introspection needs without extra dependencies. phpstan/phpdoc-parser is often used directly for PHPDoc parsing, and symfony/property-info provides property metadata that may coexist with TypeInfo. Symfony TypeInfo is a good fit when you want a structured Type model with factories, casting, identification checks, and satisfaction conditions.
- How do I test symfony/type-info integration in a Laravel app?
- Write unit tests that call TypeResolver::create()->resolve() on reflection targets and raw strings, then assert on the resulting Type. Add regression tests for recursive aliases, union and intersection accepts(), shape keys with quotes or backslashes, class constants, and global namespace class names. Use (string) $type for readable debugging output and keep a small Artisan diagnostic command if it helps your team.