Description
With Symfony 4 requiring PHP 7.1, strict typing could be introduce to reduce potential bugs, help with documentation and make the code more robust in general. However, since most of the code in Symfony also needs to run on older PHP versions until 2021 (when Symfony 3.4 is EOL'd), it's not yet practical to enforce strict typing in existing code, even for Symfony 5 where BC breaks would be acceptable.
To work around this issue, strict typing could be required for new components (e.g. the messenger
component), since they won't be ported to a Symfony version designed to run on PHP < 7.1. Optionally, the requirement could be extended to new classes for existing components to ensure new code is strictly typed in general: in most cases, new classes even for existing components wouldn't be ported to older Symfony versions. If so, the requirement should be relaxed for those cases.
What would strict typing entail:
declare(strict_types=1)
on top of the file to completely disable type coercion,- scalar type hints (including nullable,
void
, excludingobject
since PHP 7.2 isn't required) - Strict comparisons should be the norm with operators like
==
and!=
only being used in exceptional cases.