Preparing Your Apps and Bundles for Symfony 6

According to Symfony Release Process, every two years Symfony releases the last version of a branch (X.4) and the first version of the next branch (Y.0) at the same time. That will happen at the end of November 2021, when both Symfony 5.4 and Symfony 6.0 will be released. The main difference between them is that Symfony 5.4 will still contain all deprecated features and you can use it in applications using those deprecated features. Symfony 6.0 removes all deprecated features. You'll need to upgrade to 5.4 first, remove all deprecations in your code and then upgrade to 6.0. Introducing PHP Types Everywhere This time, both Symfony 5.4 and 6.0 will include another change that might have a big impact in your applications: they add PHP types in all properties, arguments and return values of methods whenever possible. This was a titanic multi-year effort led by Nicolas Grekas and Alexander M. Turek that could be completed in time for Symfony 5.4 and 6.0. The following is a real example of the impact of this change in your applications. If you have a user class implementing Symfony's UserInterface, your code will probably include this:

    1

2 3 4 5 6 7 8 9 10 11 12 13 14 // src/Entity/User.php namespace App\Entity;

use Symfony\Component\Security\Core\User\UserInterface;

class User implements UserInterface { // ...

public function getRoles()
{
    // ...
}

}

This is no longer correct in Symfony 5.4/6.0. The reason is that Symfony has added the array return type to the getRoles() method. Because of how types work in PHP, this means that it's mandatory for you to add the return type in your code:

    1

2 3 4 public function getRoles(): array { // ... }

Adding PHP Types in your Own Code Adding all the required PHP types in your applications can be a time-consuming and cumbersome task. In order to make it easier, Symfony will provide several tools: When upgrading to Symfony 5.4, you'll see deprecation messages whenever a missing type in your code would cause a PHP error when upgrading; The ErrorHandler component includes a little command utility called patch-type-declarations which automatically adds the required return types in your code; For third-party open source packages/bundles, the upgrade process is similar but you need to follow some extra steps to avoid backward compatibility breaks. The whole upgrade process for Symfony apps and open source bundles is explained in detail in the following blog post published by Wouter de Jong, a Symfony Core Team member: Symfony 6: PHP 8 Native Types & Why we Need YOU If you are an open source package/bundle developer we need your help. Please, test your bundles with Symfony 5.4 and 6.0 as soon as possible and report any problems in this meta issue in the Symfony repository. Depending on the received feedback, we might postpone some PHP type changes until Symfony 7.0. Thanks for your help!

                Sponsor the Symfony project.

http://feedproxy.google.com/~r/symfony/blog/~3/uXBX_4O0CUw/preparing-your-apps-and-bundles-for-symfony-6

Utworzony 4y | 17 wrz 2021, 09:20:22


Zaloguj się, aby dodać komentarz

Inne posty w tej grupie

SymfonyOnline June 2025: Inside a Financial App Breach: Debugging a Million-Dollar Bug

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

22 kwi 2025, 13:50:03 | Symfony
New in Symfony 7.3: Invokable Commands and Input Attributes

This is the first article in a series showcasing the most important new features introduced by Symfony 7.3, which will be released at the end of May 2025.

22 kwi 2025, 09:10:36 | Symfony
A Week of Symfony #955 (April 14–20, 2025)

This week, the upcoming Symfony 7.3 version improved the AsAlias attribute by adding a new argument, introduced Clock support for UriSigner, and refined the return type of the ContainerInterface::get(

20 kwi 2025, 08:30:06 | Symfony
SymfonyOnline June 2025: Rethinking File Handling in Symfony

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

16 kwi 2025, 16:30:02 | Symfony
SymfonyLive Paris 2025: Recap and replay!

SymfonyLive Paris 2025 took place three weeks ago — a big thank you to everyone who joined us! The conference was held entirely in French, and now you can relive the best moments: replays, hig

15 kwi 2025, 14:50:24 | Symfony
A Week of Symfony #954 (April 7–13, 2025)

This week, Symfony 7.3 entered its "feature freeze" period in preparation for its release at the end of May 2025. Development activity focused on refining and polishing its new features, including a n

13 kwi 2025, 09:40:02 | Symfony
SymfonyOnline June 2025: What's New in Symfony 7.3

SymfonyOnline June 2025 is almost here, starting in almost 2 months on:

June 10-11: Workshop days. It is possible to attend 1 two-day training or 2 one-day trainings. June 12-13: Online confe

10 kwi 2025, 16:40:34 | Symfony