What Is New in Symfony 7.0
Symfony 7.0 is a major release that modernizes the framework by removing deprecated features and introducing new capabilities. It focuses on cleaner code, better type safety, and improved developer experience. This version sets a new baseline for future development.
| Category | Key Changes |
|---|---|
| New Features | MapRequestPayload attribute, Clock component, HtmlSanitizer component, Symfony Bundle for API Platform. |
| Improvements | Stronger type hints, fluent methods in Console, better HttpClient retry, UX improvements. |
| Deprecations Removed | All code deprecated since Symfony 6.2/6.3 has been dropped, including legacy Doctrine connection methods and old validator annotations. |
| Requirements | PHP 8.2 or higher is now mandatory. |
What are the new components and attributes?
Symfony 7.0 introduces several new tools designed for modern web development. The MapRequestPayload attribute is a standout, providing a streamlined way to validate and inject request data directly into controller arguments.
The new Clock component abstracts time, making testing time-dependent behavior much simpler. The HtmlSanitizer component offers a secure way to clean user-generated HTML, which is crucial for applications with rich text input.
For API development, a dedicated Symfony Bundle for API Platform is now included, simplifying integration. In practice, these additions reduce boilerplate code and enhance security out of the box.
How has type safety been improved?
Type declarations have been significantly strengthened across many core classes and methods. This means more string, int, bool, and array return types and parameter hints in contracts.
For developers, this leads to clearer code and better IDE support. It matters because it catches potential type-related bugs earlier in the development cycle. The changes are mostly internal but promote writing more robust applications.
What deprecated features were removed?
All features deprecated in Symfony 6.2 and 6.3 have been completely removed. This cleanup is a major part of the release, resulting in a leaner codebase.
Key removals include:
- Legacy methods for accessing the Doctrine connection, like
getConnection(). - Old validation annotations using the
@Assert\*format without the#[]syntax. - The
UidFactoryclass and theallowEmptyStringvalidation constraint. - Support for Doctrine's
PdoSessionHandler.
If your project has been free of deprecation warnings since updating to 6.2/6.3, the upgrade path should be straightforward.
What improvements were made to existing components?
Several components received quality-of-life upgrades. The Console component now has fluent setters for commands, allowing method chaining like $this->setName('foo')->setDescription('...').
The HttpClient gained more flexible retry strategies, letting you define conditions based on both the response and the exception. The UX components, like Turbo and Live, saw various stability and feature enhancements for a smoother real-time experience.
These improvements are about polishing the developer experience. They don't change fundamental behavior but make the framework more pleasant and efficient to work with daily.
FAQ
What is the minimum PHP version for Symfony 7.0?
You must run PHP 8.2 or higher. This allows the framework to use the latest PHP features for performance and type safety.
What is the MapRequestPayload attribute and why should I use it?
It's a new controller argument attribute that maps and validates JSON, XML, or form data to a typed object. Use it to replace manual calls to SerializerInterface and ValidatorInterface, making your controllers cleaner.
My app was on Symfony 6.4 with no deprecation warnings. Will upgrading be difficult?
It should be very smooth. Symfony 7.0 only removes features that were deprecated in 6.2 and 6.3. If you had no warnings, the breaking changes likely don't affect your codebase.
Is the old @Annotation validation syntax still supported?
No, support for the old @Assert\Email style annotations in validation has been removed. You must use the PHP 8 attribute syntax: #[Assert\Email].
How does the new Clock component help in testing?
It provides a ClockInterface that abstracts time(), sleep(), and DateTimeImmutable objects. You can mock time in tests, making scenarios like checking expiration logic or time-based triggers deterministic and reliable.