DEV Community

Discussion on: PHP Tips and Tricks

Collapse
 
nicolus profile image
Nicolas Bailly

I keep going back and forth on the "return early" style.

The main advantage for me is that you get back 4 precious spaces at the beginning of every line in your "main" path. The disadvantage as you said is it's easier to see a return statement at the end of the function and miss the fact that it could have returned something else entirely.

At the end of the day, I guess if either of those is a real issue, it just means your method is too complicated and it's time to refactor by adding a new simpler method.

Collapse
 
leob profile image
leob

"Early return" FTW ;)