-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Enforce return type hints for Symfony 4+ #24882
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
What if the return type is object or mixed? |
We cannot enforce it for all refactorings, as our BC policy is more important (and this is why the previous PR has not added them everywhere). But for any new API we add, we should indeed add types whenever we can. And this is nothing new: our existing policy in 3.x is already to add types whenever we can. The only difference is that requiring PHP 7.1+ in Symfony 4 means that |
About void... I'm introducing one in https://github.com/symfony/symfony/pull/24926/files#diff-e88ad8ede40599bea0592b1113c4452cR383 :) but im leaning to reverting now.. To me a missing return type implies mixed return type. We should embrace it as of 4.1 for new public API at least. In general.. im not sure it's worth for current/new private API nor current final public API. I guess it doesnt hurt. edit:
Right.. agree 👍 |
Closing as code style issues are discussed on PR, and as @stof said we embrace new language feature at a slow pace because of the long term maintenance we (the core team) endorse for the community. |
In #24722 there is a massive change that turns docblocks into type hints. I think it would be a good idea to make an automated test in coding standard for it.
It would make it simpler to make sure that all new features and refactorings use return type hints.
Also as more and more code gets converted to type hints it will be harder and harder to find the places where type hints are missing.
Even if it were too hard to do it all at once, it would be possible to keep in branch, rebase and use it every now and then in newly created PR adding more type hints.
What do you think? Is it feasible? I wouldn't mind making a PR for the CS check, if it makes sense.
The text was updated successfully, but these errors were encountered: