Page 1 of 1
Which php method is better?
Posted: Thu Oct 29, 2009 5:10 am
by jaoudestudios
Which method is better?
Code: Select all
if ($x == 1)
{
return true;
}
else
{
return false;
}
or
thanks
Re: Which php method is better?
Posted: Thu Oct 29, 2009 6:43 pm
by Jonah Bron
Um, I think that on the hardware level, "return $x==1" is slightly better, plus there is slightly less interpreting. Though, it's not so good for readability. Maybe "return ($x==1)"?
Why?
Re: Which php method is better?
Posted: Fri Oct 30, 2009 2:40 am
by jaoudestudios
We're having a debate at work.
I agree with what you said, may be less interpreting but also less readable.
Thanks!

Re: Which php method is better?
Posted: Fri Oct 30, 2009 2:48 am
by VladSun
jaoudestudios wrote:We're having a debate at work.
I agree with what you said, may be less interpreting but also less readable.
Thanks!

I think that the "if" version is less readable

I'd always use the "single-line-return" version.
Re: Which php method is better?
Posted: Fri Oct 30, 2009 10:20 am
by pickle
In your position, I'd have used:
Still one line, and still readable