December 12, 2019 Javier Eguiluz

If you follow the Living on the Edge category of this blog, you'll find all the latest and greatest new features of each Symfony version. Big and small features that help you create your projects while having the best possible developer experience.

However, this is only part of the development activity needed to create and maintain Symfony. In this blog post we'll mention some changes that required hundreds of hours of work but remained invisible because they are not part of a shiny new feature.

Added PHP Type Declarations¶ PHP type declarations (or "type hints") add information about the data types of the function and method arguments. Symfony code didn't have type declarations yet because, according to the Symfony Release Process, we cannot add the latest PHP features right away and we need to wait until certain Symfony versions are released to make those changes. Symfony 5.0 was the perfect moment to add these type declarations to our entire code base. This was a painstaking process because, even if some work could be automated, each change had to be reviewed manually. The reason is that it's not only about removing PHPdoc comments and adding the types to the method arguments. You also need to check the rest of the code to look for data type castings. For example: 1 2 3 4 5 6 7 8 -/** - * @param bool|null $enabled - */ -public function setStrictRequirements($enabled) +public function setStrictRequirements(?bool $enabled) { - $this->strictRequirements = null === $enabled ? null : (bool) $enabled; + $this->strictRequirements = $enabled; Check out the Pull Request #32179 to get an idea of the size of this change. Tens of thousands of lines were changed in thousands of files and tens of hours were spent reviewing and merging everything. Thanks to @jschaedl, @Simperfit, @Tobion, @Matts, @smoench, @vudaltsov, @julien57, @azjezz, @tigitz, @andreia, @thomasbisignani, @lyrixx, @xabbuh for contributing these changes. Special thanks to @derrabus for coordinating the work and to @nicolas-grekas for doing the actual merge and conflict solving.

Added PHP Return Types¶ PHP return types allow functions and methods to specify the data type of their returned values. We considered adding these return types in Symfony 5.0 but we finally didn't do it because of two reasons: The burden this would put on the community is immense, because third-party libraries and bundles should also be updated to be compatible with this new Symfony code that includes return types. In other words, Symfony should be the last to add these return types, not the first one.

Given the complexity and flexibility of Symfony's code base, we'd need return type covariance, which is only available in PHP 7.4 (Symfony 5.x requires PHP 7.2). In any case, we have a plan to add these return types in Symfony 6.0. Check out the Pull Request #33236 to see the clever trick used to add these return types automatically thanks to the DebugClassLoader . Special thanks to @fancyweb for fixing all current return types defined in PHPdoc comments (see Pull Request #30323).