top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the preferred way to write this if statement, and why? if( 5 == $someVar ) or if( $someVar == 5 )

+3 votes
311 views
What is the preferred way to write this if statement, and why? if( 5 == $someVar ) or if( $someVar == 5 )
posted Sep 27, 2015 by Vrije Mani Upadhyay

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

The former, as it prevents accidental assignment of 5 to $someVar when you forget to use 2 equalsigns ($someVar = 5), and will cause an error, the latter won't.

answer Dec 31, 2015 by Manikandan J
...