New in Symfony 7.2: Redesigned TypeInfo Component

Contributed by
Mathias Arlaud
in
#57630
and #58852

Symfony features are covered by the Backward Compatibility Promise, which ensures
that you can safely upgrade between minor versions (e.g. from 7.0 to 7.1, 7.2, etc.)
without facing any breaking change.

However, some selected features are introduced as experimental features. These
are features that could change their API and other behavior based on the feedback
received about them. This is what happened to the TypeInfo component, which was
introduced as experimental in Symfony 7.1.

The TypeInfo component extracts information about PHP types from method arguments,
return types, and raw strings. After using it for a few months in real applications
and integrating it into other packages and libraries, we decided to improve it
in several ways:

Introduced CompositeTypeInterface and WrappingTypeInterface to
better describe whether a type is composed by several types or wraps one;
Added a NullableType, which extends UnionType and is a WrappingTypeInterface,
making it much simpler to recognize a nullable type and retrieve its related non-nullable type;
Removed the __call() method that CollectionType and GenericType
used to forward methods to their wrapped type (because now it’s simpler
to know if a type wraps another one);
Rename is*() to satisfy*() and add CompositeTypeInterface::composedTypesSatisfy()
and WrappingTypeInterface::wrappedTypeSatisfy() methods;
Added many checks to prevent invalid type constructions.

We’re now confident that the component has the right architecture and behavior.
That’s why we no longer consider it an experimental feature, and you can safely
use it knowing that we won’t introduce breaking changes to it.

Sponsor the Symfony project.

Symfony Blog

Read More

Latest News

PHP-Releases

PHP 8.4.1 released!

PHP 8.1.31 released!

PHP 8.3.14 released!

PHP 8.2.26 released!

Generated by Feedzy