Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

return 1 and return 0 VS return true and return false [closed]

Tags:

php

Me and my colleague were arguing about how to return booleans in PHP functions.

Which one do you use and why?

return 0;
return 1;

OR

return false;
return true;

It is clear that first variant it wouldn't work fine in programming languages with strict typing, but it will work absolutely fine in PHP in most cases.

I use first more logical variant, but I couldn't come up with good arguments but "return boolean if you want to return a boolean" and "more readable", but they are quite weak.

like image 717
Tim Avatar asked Jan 10 '13 15:01

Tim


1 Answers

  • option with true / false more popular
  • harder to get confused in the code
  • return Boolean true / false is clear to all, rather than 1/0
like image 116
gJamDev Avatar answered Sep 22 '22 00:09

gJamDev