Jump to content

acceptable practice SOLVED with thanks in final post


niche

Recommended Posts

Is this acceptable practice (letting the 1st condition shield the second)?

 <?phpif (isset($var) and $var == "Y") {echo "here";}?>

Obviously, reversing the conditions produces an error, but this way doesn't and it's convenient. Issues, or do the ends justify the the means in this case?

Link to comment
Share on other sites

That's called short-circuiting, which both PHP and Javascript support. If there are multiple conditions separated by AND or OR, and one of them evaluates to a value that will "solve" the entire statement (false for AND, true for OR), then evaluation stops after that condition. So if you have an AND condition and the first expression evaluates to false, it will not evaluate the other expressions. That's why this works also: $result = mysql_query($sql) or exit(mysql_error()); Since that is an or operator, if the first expression evaluates to true it does not evaluate (execute) the next one. The error only shows if the first expression evaluates to false.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...