What Is New in Symfony 4.0
Symfony 4.0 is a major modernization release focused on speed, simplicity, and a better developer experience. It introduces a new project structure, a leaner default kernel, and powerful new tools for service configuration.
| Category | Key Changes |
|---|---|
| New Features | Symfony Flex, new project directory structure, microkernel by default. |
| Improvements | Faster default configuration (YAML to PHP), improved autowiring, environment variable handling. |
| Deprecations | Legacy directory structures (app/Resources/, web/), some container parameters. |
| Removed | Bundle inheritance, some core bundles (Assetic, Swiftmailer as default), legacy PHP support. |
How Did The Project Structure Get Simplified?
The classic app/Resources/ and web/ directories are gone. The new structure is flatter and more logical. Configuration, templates, and translations now live directly in config/, templates/, and translations/ at the root level.
This matters because it reduces cognitive load. Everything has a single, predictable place. The public document root is now public/, which is a standard across many modern frameworks and makes deployment straightforward.
Before and After Example
# Symfony 3 Structure
app/Resources/views/
web/app.php
web/bundles/
# Symfony 4 Structure
templates/
public/index.php
assets/
What Is Symfony Flex and Why Use It?
Symfony Flex is a new plugin for Composer that revolutionizes how you manage applications. It's not a bundle but a Composer plugin that automates common tasks when installing or removing packages.
When you require a recipe package, Flex can automatically create configuration files, update .env, and even create directories. In practice, this means you can spin up a fully functional feature, like an API or admin panel, with just one or two Composer commands.
composer require api
# Flex automatically configures API Platform, routes, and more.
Why Switch Configuration from YAML to PHP?
Default configuration format shifted from YAML to PHP for significant performance gains. PHP files can be cached natively by the OPcache, leading to faster application boot times, especially in production.
You can still use YAML, XML, or annotation formats if you prefer. The framework now generates PHP configuration files by default when using commands like make:controller. This change reflects Symfony's focus on runtime performance for real-world applications.
How Does Autowiring Work Better Now?
Service autowiring is now more powerful and intuitive. Type-hinting services in your constructor arguments is often all you need. The container will automatically inject the correct service without any manual configuration.
A major improvement is the use of service id names. You can now reference services by their class or interface name consistently. This reduces verbose service definition and makes code more refactor-friendly.
# Before: Manually wiring a service
services:
App\Mail\NewsletterGenerator:
arguments: ['@mailer']
# After: Relying on autowiring
# Just type-hint the MailerInterface in the constructor.
# No YAML or XML needed.
FAQ
Is Symfony 4.0 a complete rewrite? Will my old projects break?
No, it's not a rewrite. It's an evolution with removed deprecations and new defaults. Existing Symfony 3.x applications following best practices will require an upgrade path, as deprecated features have been removed. It's a major version, so breaking changes are expected.
Do I have to use the new directory structure?
For new projects created with symfony new, yes, this is the default and recommended structure. For upgrading existing projects, you can adapt gradually, but moving to the new structure is advised for long-term compatibility.
What happened to the web/ directory and app.php front controller?
They have been renamed to public/ and public/index.php to follow current PHP community standards. This aligns with other frameworks and simplifies server configuration.
Are bundles still used in Symfony 4?
Yes, but their role has changed. In your application, you typically need only one bundle--the App bundle. Third-party packages still ship as bundles, but Flex recipes handle their configuration, so you rarely need to manually enable them.
Can I upgrade from Symfony 2.8 or 3.x directly to 4.0?
Directly, no. You must first upgrade to the latest Symfony 3.4 release, resolve all deprecation notices, and then follow the migration guide to 4.0. The process is methodical and well-documented.