Conditional statements with empty conditions

I ran into this issue, but detected it by accident.

The following I believe will work.

<?php
if($something ==)
{
     print("hi");
}
?>

This was suppose to say if($something == "yes"), however it didn't trigger an error in my application. I suppose it was checking that $something was NULL, but I'm not sure.

The way to ensure this won't happen is to reverse the statement.

<?php
if(== $something)
{
     print("hi");
}
?>

Actually, this is to prevent errors by using good coding practices. The above would never make sense, because there needs to be something for $something to equal.

if(3 == $value)

In the example above, by putting values on the left and variables on the right, you can prevent these kind of errors in the future.

Page Comments (Click to edit)

Design by N.Design Studio, adapted by solidGone.org (version 1.0.0)
Powered by pmwiki-2.2.0-beta65