Javier Eguiluz · Symfony

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.

PHP 8 is packed with new interesting features, such as union types, match expressions and constructor property promotion. However, the most sought-after new feature is built-in attributes (also called annotations).

Symfony 5.2 will include support for PHP 8 attributes to define routes and required dependencies. If you already use annotations, the transition will be seamless:

The same Route class provides support for Doctrine annotations and PHP attributes, so you don't need to change the class import. The only required change is to update the annotation syntax, which now looks like this: #[ ... ] That's all! Your application is now using native PHP attributes and you can uninstall dependencies like doctrine/annotations if you don't use them elsewhere.

We also added a #[Required] attribute to replace @Required annotation and tell Symfony that a property/method holds a required dependency:

PHP is entering a new golden era with the release of PHP 8 and Symfony will be fully-compatible since day one. These attributes are just the beginning and we'll add many more (e.g. for validation) in the coming weeks.

Log in to add a reaction to this post

❤️ Help the Symfony project!

As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.

Comments are closed.

To ensure that comments stay relevant, they are closed for old posts.

Read the original on symfony.com ↗