What Is New in Symfony 5.0
Symfony 5.0 is a cleanup release that removes deprecated features introduced in earlier 4.x versions. The core focus is on a leaner codebase and modern PHP practices, requiring PHP 7.2.5 or higher.
| Category | Key Changes |
|---|---|
| New Features | New Uid component, new IsGranted attribute for security, @ParamConverter as PHP attribute. |
| Improvements | Cleaner default directory structure, removal of src/ subnamespaces, updated recipes. |
| Deprecated Code Removal | All code deprecated in Symfony 4.x is gone. This includes container parameters, bundle inheritance, legacy form features, and more. |
| Dependency Updates | Twig 3, Doctrine Bundle 2, PHPUnit 8+ support, and updated many third-party package constraints. |
What deprecated features were removed in Symfony 5?
All features marked as deprecated in Symfony 4.x versions have been completely removed. This is the main theme of the 5.0 release. In practice, this means your application will break if you haven't addressed these deprecation notices during your 4.x development cycle.
Key Removals Include:
- Container Parameters: Global parameters like
container.dumper.inline_class_loaderandsession.save_pathare no longer defined by default. - Bundle Inheritance: The
getParent()method in bundles is no longer supported. - Legacy Form Features: Support for the
choicefield'schoices_as_valuesoption and theformatoption in Date/Time types is removed. - FrameworkBundle Templating: The
templatingcomponent integration is gone; use Twig instead. - Validator: The
checkMXandcheckHostoptions for theEmailconstraint are removed.
Are there any new components or features added?
Yes, Symfony 5.0 introduces a few targeted additions alongside the major cleanup. The most notable is the new Uid component, which provides utilities to generate and work with UUIDs and ULIDs.
For developers using annotations, there's a new @IsGranted attribute from SecurityBundle that simplifies access control in controllers. The @ParamConverter annotation from SensioFrameworkExtraBundle can now also be used as a native PHP 8 attribute.
The default project structure is also cleaner. For example, the generated src/Controller/ class no longer lives under a redundant App\ subnamespace, making it simply App\Controller.
What are the minimum PHP and third-party package requirements?
Symfony 5.0 requires PHP 7.2.5 or higher. This matters because it allows the framework to rely on modern PHP features without polyfills for older versions.
Third-party bundles and components have also bumped their minimum versions. Key updates include Twig 3, Doctrine Bundle 2, and PHPUnit 8. If you're upgrading, you need to check your composer.json for compatibility with these new constraints. The Flex recipes have been updated to reflect these changes.
How does the directory structure change in a new Symfony 5 project?
The new structure is flatter and removes some historical quirks. When you create a fresh Symfony 5.0 project, you'll notice the src/ directory no longer has the redundant App\ subdirectory structure inside it.
Previously, a controller lived in src/App/Controller/. Now, it's directly in src/Controller/. This change simplifies autoloading and aligns better with standard PHP practices. Existing projects aren't forced to change, but new ones will follow this pattern.
FAQ
Is Symfony 5.0 a major rewrite with breaking changes?
No, it's not a rewrite. It's a stabilization release that removes code previously marked as deprecated in the 4.x series. The core architecture remains the same, but you must fix deprecations before upgrading.
Can I upgrade directly from Symfony 3.4 or 4.0 to 5.0?
Directly, no. You must first upgrade to the latest Symfony 4.4 release and fix all deprecation notices. The 4.4 version is a Long-Term Support (LTS) release that includes all the deprecation warnings you need to address for a smooth jump to 5.0.
What happened to the templating component (PHP) in Symfony 5?
The integration of the templating component (for PHP templates) in FrameworkBundle has been removed. Symfony now uses Twig as its sole official templating engine. You can still use PHP templates if you manually configure the component, but it's no longer the default.
Are there any new security features in Symfony 5.0?
The main security addition is the @IsGranted attribute, provided by the SensioFrameworkExtraBundle. It offers a more concise way to secure controller actions compared to the traditional @Security annotation or in-code checks.
What is the Uid component used for?
The new Uid component generates and manipifies unique identifiers like UUIDs (versions 1, 3, 4, 6) and ULIDs. It's a lightweight, framework-agnostic utility that can be used independently in any PHP project for robust ID generation.