symfony / type-info
Extracts PHP types information.
v8.1.0
2026-05-29 05:06 UTC
Requires
- php: >=8.4.1
- psr/container: ^1.1|^2.0
Requires (Dev)
- phpstan/phpdoc-parser: ^1.30|^2.0
Conflicts
- phpstan/phpdoc-parser: <1.30
This package is auto-updated.
Last update: 2026-06-05 06:51:12 UTC
README
The TypeInfo component extracts PHP types information.
Getting Started
composer require symfony/type-info
composer require phpstan/phpdoc-parser # to support raw string resolving
<?php use Symfony\Component\TypeInfo\Type; use Symfony\Component\TypeInfo\TypeIdentifier; use Symfony\Component\TypeInfo\TypeResolver\TypeResolver; // Instantiate a new resolver $typeResolver = TypeResolver::create(); // Then resolve types for any subject $typeResolver->resolve(new \ReflectionProperty(Dummy::class, 'id')); // returns an "int" Type instance $typeResolver->resolve('bool'); // returns a "bool" Type instance // Types can be instantiated thanks to static factories $type = Type::list(Type::nullable(Type::bool())); // Type classes have their specific methods Type::object(FooClass::class)->getClassName(); Type::enum(FooEnum::class, Type::int())->getBackingType(); Type::list(Type::int())->isList(); // Every type can be cast to string (string) Type::generic(Type::object(Collection::class), Type::int()) // returns "Collection<int>" // You can check that a type (or one of its wrapped/composed parts) is identified by one of some identifiers. $type->isIdentifiedBy(Foo::class, Bar::class); $type->isIdentifiedBy(TypeIdentifier::OBJECT); $type->isIdentifiedBy('float'); // You can also check that a type satisfies specific conditions $type->isSatisfiedBy(fn (Type $type): bool => !$type->isNullable() && $type->isIdentifiedBy(TypeIdentifier::INT));
Sponsor
This package is looking for a backer.
Help Symfony by sponsoring its development!