What Is New in Symfony 3.3
Symfony 3.3 introduces a set of new features, improvements, and deprecations that streamline development and modernize the framework's core components. The focus is on enhancing the developer experience, particularly with service configuration and dependency injection. Here is a summary of the key changes.
| Category | Key Changes |
|---|---|
| New Features | Simplified service configuration, autowiring by type and name, new AbstractController, PSR-4-based service discovery, environment variable processors. |
| Improvements | Enhanced console component with lazy commands, improved error pages, smoother DX with Flex, updates to Security, Form, and Serializer components. |
| Deprecations | Legacy service container configuration, some method signatures, and old patterns are deprecated in favor of new, simpler approaches. |
How Did Service Configuration Get Simpler?
The service container configuration received major simplifications. The new _defaults and _instanceof keys in YAML allow you to apply common configuration to many services at once, reducing repetition.
Autowiring was significantly upgraded. It now supports autowiring by type and by name, making it much more practical for real-world applications. You can also use the autowire() and autoconfigure() methods in PHP configuration for the same benefits.
Example of Simplified YAML Configuration
services:
_defaults:
autowire: true
autoconfigure: true
public: false
App\:
resource: '../src/*'
exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'
What Are the New Helper Classes and Components?
A new AbstractController was introduced to replace the old Controller class. It provides the same convenience methods but uses the service container's autowiring, promoting better practices.
The Console component now supports lazy-loading of command classes. This means commands are instantiated only when they are actually called, which improves performance for applications with many commands.
Environment variable processors were added, providing a way to validate and process environment variable values (e.g., converting strings to integers) directly within your configuration.
What Deprecations Should I Be Aware Of?
Several patterns from older Symfony versions are now deprecated. This includes the old way of configuring services without using _defaults or _instanceof. The legacy Controller class is also deprecated in favor of AbstractController.
Some method signatures in the HttpKernel and Security components have been updated, with the old ones deprecated. The error page system has been refactored, deprecating the old exception handling templates.
In practice, running your application with the Symfony Profiler will highlight these deprecations, giving you a clear path to update your code before Symfony 4.0.
FAQ
What is the main benefit of the new service configuration defaults?
The main benefit is drastically reduced configuration boilerplate. Using _defaults and PSR-4 service discovery means you rarely need to manually define a service unless it requires specific, non-standard arguments.
Should I immediately switch to AbstractController?
Yes, it's a straightforward change. Extend AbstractController instead of Controller. Your existing helper methods like render() or getParameter() will keep working, but your controller will be properly autowireable.
How do environment variable processors work?
They are functions you can apply to environment variables in your configuration. For example, env('int:MY_PORT') ensures the value is treated as an integer. This replaces manual casting in your code.
What happens if I ignore the deprecation warnings?
Your application will continue to work in 3.3, but it will break when you upgrade to Symfony 4.0. The deprecation notices are a crucial migration guide, so addressing them early saves future effort.
Is the new lazy command feature automatic?
No, you need to explicitly implement the Command interface and configure the command as a service, tagging it with console.command. The framework then handles the lazy loading automatically from that point.