What Is New in Symfony 6.0
Symfony 6.0 is a major release that modernizes the framework by requiring PHP 8.1 and removing a significant amount of legacy code. This streamlines the codebase and unlocks new language features for developers. The focus is on cleaner, more type-safe applications.
| Category | Key Changes |
|---|---|
| New Features | Stronger type system with PHP 8.1, PSR-7/17 support in HttpClient, new Uid component. |
| Improvements | Faster, more reliable ux.symfony.com integration, enhanced Cache and Lock components. |
| Deprecations Removed | All code deprecated before Symfony 5.4 has been dropped, including legacy container configuration and old session handling. |
| Requirements | PHP 8.1 or higher is now mandatory. |
Why is PHP 8.1 now a hard requirement?
Symfony 6.0 mandates PHP 8.1 to fully utilize its modern features like enums, readonly properties, and first-class callable syntax. This allows the framework to drop compatibility layers and legacy code, resulting in a leaner and more performant core. For developers, it means writing more expressive and robust code from the start.
What legacy code was cleaned up in this release?
The release removes all features that were deprecated before Symfony 5.4. Major cleanups include the old session service and SessionInterface, the legacy PhpFilesCache adapter, and support for Doctrine annotations. The container configuration no longer accepts the old service and prototype XML namespace.
In practice, this forces applications to use the modern, injected RequestStack for session access and the newer, more efficient caching adapters. It's a significant step towards a simpler framework architecture.
How does the type system get stronger?
Symfony 6.0 embraces PHP 8's type system by adding return type declarations to almost all methods across the framework's codebase. This includes methods in the KernelInterface, Command class, and various event listeners.
This matters because it catches type-related bugs earlier and improves IDE support. If you've been extending Symfony classes, you'll need to update your child methods to match these new signatures.
What are the notable component additions?
HttpClient gains PSR-18 compatibility
The HttpClient component now implements PSR-18 (Psr\Http\Client\ClientInterface), allowing it to be used as a standard HTTP client in any PSR-18 compatible library. It also provides PSR-17 factories for creating requests and streams.
New Uid component for identifier generation
The new Symfony\Component\Uid component provides tools to generate and work with unique identifiers like ULIDs and UUIDs. It's fast, lightweight, and offers utilities for ramsey/uuid interoperability.
FAQ
Is upgrading to Symfony 6.0 difficult?
The main effort involves updating your PHP version to 8.1+ and addressing any use of code that was deprecated before Symfony 5.4. The Symfony upgrade tool and the deprecation detector can automate much of this process.
Can I still use annotations for routing and configuration?
Yes, but you must migrate from Doctrine Annotations to the native PHP attributes. Symfony 6.0 removes support for the legacy annotation format, but the switch to attributes is straightforward and offers better performance.
What happened to the old session service?
The session service and SessionInterface alias were removed. You must now inject the RequestStack service and call getSession() on the current request to access the session.
Does the Cache component still work the same way?
Mostly, but the PhpFilesCache adapter was removed in favor of PhpMarshallerCache. You should update your cache configuration to use the newer adapter, which is more reliable.
Are there any changes to how forms are handled?
The core form functionality remains stable. However, underlying type changes in extended classes (like added return types) may require you to update your custom form types if you override certain methods.