What Is New in Symfony 7.3
Symfony 7.3 delivers a focused set of enhancements, primarily improving developer experience and component interoperability. The update introduces new attributes, expands existing component capabilities, and continues the framework's modernization efforts.
| Category | Key Changes |
|---|---|
| New Features | New #[MapQueryParameter] attribute, UidValueResolver,
#[WithHttpStatus] attribute, and LazyGhost serialization support. |
| Improvements | Enhanced HttpClient retry strategies, Mailer HTML to text conversion,
Process timeouts, and Webhook component refinements. |
| Deprecations | Deprecated the allow_empty_string context option in the
DateTimeNormalizer. |
How Does Symfony 7.3 Simplify Controller Arguments?
The new #[MapQueryParameter] attribute automatically maps query string parameters to controller
method arguments. This removes boilerplate code for fetching and converting request data, making controllers
cleaner and more declarative.
use Symfony\Component\HttpKernel\Attribute\MapQueryParameter;
public function index(
#[MapQueryParameter]
string $search,
#[MapQueryParameter]
int $page = 1
) {
// $search and $page are automatically populated from the query string
}
You can specify filtering options like filter for validation and array to handle
comma-separated lists. This approach is more integrated and type-safe than manually accessing the
Request object.
What New Resolver and Attributes Were Added?
UidValueResolver
A new UidValueResolver allows you to type-hint controller arguments with Uuid or
Ulid objects. The resolver automatically converts string identifiers from the request into the
corresponding object.
WithHttpStatus Attribute
The #[WithHttpStatus] attribute lets you define the HTTP status code for a specific exception class
directly on the exception itself. This centralizes the response logic.
use Symfony\Component\HttpKernel\Attribute\WithHttpStatus;
#[WithHttpStatus(404)]
class ProductNotFoundException extends \RuntimeException
{
}
How Are HttpClient and Mailer Improved?
Symfony's HttpClient now supports more granular retry strategies using the
RetryableHttpClient. You can define different retry logic based on HTTP methods, status codes, or
specific exceptions, giving you finer control over fault tolerance.
The Mailer component introduces an HtmlToTextConverterInterface. This allows for custom
strategies when generating plain text fallbacks from HTML email content, improving accessibility and email
client compatibility.
What About Serialization and Process Components?
The Serializer component now supports LazyGhost objects from the PropertyAccess component. This
means these virtual proxy objects can be properly normalized and denormalized, which is crucial for applications
using advanced data lazy-loading patterns.
In the Process component, the setIdleTimeout() method now accepts null to disable the
timeout entirely. This provides more flexibility for long-running processes where only the total execution time
should be limited.
FAQ
What is the main benefit of the #[MapQueryParameter] attribute?
It eliminates manual fetching
and type conversion of query parameters in controllers. By declaring parameters directly as method arguments
with the attribute, your code becomes more concise, readable, and less error-prone.
Can I use the new UidValueResolver with both UUIDs and ULIDs?
Yes. The resolver automatically
instantiates either a Uuid or Ulid object based on the format of the string identifier
provided in the request path or query string.
What happens if I use the deprecated 'allow_empty_string' option?
Using the
allow_empty_string context option in DateTimeNormalizer will trigger a deprecation
notice in Symfony 7.3. It will be removed in a future version, so you should update your code to handle empty
string values before passing them to the normalizer.
How does the #[WithHttpStatus] attribute change exception handling?
It moves the
responsibility of defining an exception's HTTP status code from the exception listener or controller to the
exception class itself. This makes the intended HTTP behavior of an exception a core part of its definition.
Is the new HtmlToTextConverter in Mailer mandatory?
No, it's an optional interface for
customizing behavior. If you don't provide a custom converter, the Mailer will fall back to its default strategy
for converting HTML to plain text.