Skip to content

Explicitly return null in getUser() #23642

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

Closed
wants to merge 1 commit into from

Conversation

bocharsky-bw
Copy link
Contributor

Q A
Branch? master
Bug fix? no
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

Practically, return; and return null; is the same, but it's a good practice to explicitly return null if the method could return something. It's fine to have just return; in methods that simply do some operations and return nothing, i.e. doesn't have @return annotation. Actually, PhpStorm suggests the same.

@lyrixx
Copy link
Member

lyrixx commented Jul 24, 2017

Actually for PHP 7.1+ it's not the same...

https://3v4l.org/ZH8Z5 vs https://3v4l.org/UgH0S

@fabpot
Copy link
Member

fabpot commented Jul 24, 2017

Changing this in just one file is a no go. We should first decide to change a decision we made some years ago to never use return null and then make the change everywhere. I think it's not worth it. I prefer to postpone the change to when we week decide to use type hints for return values.

@yceruto
Copy link
Member

yceruto commented Jul 24, 2017

According to Coding Standard both methods are feasible:

Use return null; when a function explicitly returns null values and use return; when the function returns void values;

So it should depend of @return ? phpdoc?

@nicolas-grekas
Copy link
Member

Same pov as @fabpot, we may close this PR to me :)

@nicolas-grekas nicolas-grekas added this to the 4.0 milestone Jul 25, 2017
@lyrixx
Copy link
Member

lyrixx commented Jul 25, 2017

Same for me.

@lyrixx lyrixx closed this Jul 25, 2017
@bocharsky-bw bocharsky-bw deleted the patch-2 branch July 25, 2017 15:03
@bocharsky-bw
Copy link
Contributor Author

I suppose you need to open an issue about it and add it to the 4.0 milestone if you close this one, right? :)

@xabbuh
Copy link
Member

xabbuh commented Jul 25, 2017

@bocharsky-bw IIRC we "somewhere" have an open issue.

EDIT: see #17201

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants