Skip to content

unified return null usages #10717

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

Merged
merged 1 commit into from
Apr 18, 2014
Merged

unified return null usages #10717

merged 1 commit into from
Apr 18, 2014

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Apr 16, 2014

Q A
License MIT

This PR unifies the way we return null from a function or method:

  • always use return; instead of return null; (the current code base uses both);
  • never use return; at the end of a function/method.

@@ -785,7 +785,7 @@ protected function getNode($position)
// @codeCoverageIgnoreStart
}

return null;
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one could be removed

@Tobion
Copy link
Contributor

Tobion commented Apr 16, 2014

Hm I prefer explicit return null. I've met people that didn't know it's the same as return or no return and would argue null cannot be returned from this method.

@fabpot
Copy link
Member Author

fabpot commented Apr 16, 2014

Well, people need to learn PHP then.

@henrikbjorn
Copy link
Contributor

👍 being consistent and across projects, great!

@romainneutron
Copy link
Contributor

👍

@jakzal
Copy link
Contributor

jakzal commented Apr 16, 2014

👍 for this (although I could agree with @Tobion), I prefer consistency over any specific style.

@Burgov
Copy link
Contributor

Burgov commented Apr 16, 2014

i too prefer return null;, as well as explicitly returning null at the end of a function if there are other return statements in it

@cordoval
Copy link
Contributor

i am with @jakzal and @Tobion 👍

@sstok
Copy link
Contributor

sstok commented Apr 16, 2014

And what if an interface explicitly states to return either a value or null?

@aderuwe
Copy link
Contributor

aderuwe commented Apr 16, 2014

I prefer being explicit over implicit, too, but 👍 for the consistency regardless.

@fabpot
Copy link
Member Author

fabpot commented Apr 16, 2014

@sstok What do you mean? This PR is just about removing code that does not do anything.

@sstok
Copy link
Contributor

sstok commented Apr 16, 2014

Well it wasn't clear if that was the case, as it stated always use return; instead of return null; (the current code base uses both); it wasn't clear to me if this also applies when you must to return null.

@mayeco
Copy link
Contributor

mayeco commented Apr 17, 2014

@sstok if you must return null just don't use return in the function and PHP will return null when the function ends.

@stof
Copy link
Member

stof commented Apr 17, 2014

@fabpot Given that fabbot already validates this, I suggest merging the PR to avoid having such changes done by all other PRs out there

@fabpot fabpot merged commit d1d569b into symfony:2.3 Apr 18, 2014
fabpot added a commit that referenced this pull request Apr 18, 2014
This PR was merged into the 2.3 branch.

Discussion
----------

unified return null usages

| Q             | A
| ------------- | ---
| License       | MIT

This PR unifies the way we return `null` from a function or method:

 * always use `return;` instead of `return null;` (the current code base uses both);
 * never use `return;` at the end of a function/method.

Commits
-------

d1d569b unified return null usages
@fabpot fabpot deleted the return-null branch April 19, 2014 08:17
@webmozart
Copy link
Contributor

Ah, I missed this one. I disagree with this PR too. I thought that the rules were fairly simple:

  • If a method is supposed to return a value, it should contain the statement return <value>; at the end of each execution path.
  • If a method is not supposed to return a value, return; can be used to terminate the execution prematurely.

IMO, this conveys the purpose of the code much better than what is done in this PR. Of course, PHP supports what is done here, but then PHP supports a lot of confusing things (using undeclared properties etc.).

-1, FWIW.

fabpot added a commit that referenced this pull request Jun 26, 2019
…lver (Tobion)

This PR was merged into the 4.4 branch.

Discussion
----------

use proper return types in ErrorHandler and ArgumentResolver

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | tiny
| New feature?  | no <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets |
| License       | MIT
| Doc PR        |

Found those things while reviewing #31996 which missed some return types due to using `return` instead of `return null`.
It's part of fixing #17201 (due to #10717). See also #30869 that somebody was stumbling over.

Commits
-------

2f9121b use proper return types in ErrorHandler and ArgumentResolver
jderusse pushed a commit to jderusse/symfony that referenced this pull request Dec 15, 2020
This PR was merged into the 2.3 branch.

Discussion
----------

unified return null usages

| Q             | A
| ------------- | ---
| License       | MIT

This PR unifies the way we return `null` from a function or method:

 * always use `return;` instead of `return null;` (the current code base uses both);
 * never use `return;` at the end of a function/method.

Commits
-------

d1d569b unified return null usages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.