Ivo Jansch at the "Achievo blog" has wrote a post about what he calls "Defensive programming". The problem is very simple but not all developers that take care of such thing:
Look at this code:
In a test mode, for some reason or an other what happens if the $mode is not defined? Customers will receive the emails and that's not the goal.
Look now at this code:
Here, in the worst situation developers will receive the emails and customers will not be disturbed.
You're right Ivo.
Look at this code:
<?php
....
if ($mode=="test"}
{
$recipients = "developers@somedomain.ext";
}
else
{
$recipients = "customers@somedomain.ext";
}
?>
In a test mode, for some reason or an other what happens if the $mode is not defined? Customers will receive the emails and that's not the goal.
Look now at this code:
<php
....
if ($mode=="production"}
{
$recipients = "customers@somedomain.ext";
}
else
{
$recipients = "developers@somedomain.ext";
}
?>
Here, in the worst situation developers will receive the emails and customers will not be disturbed.
In essence, you have to expect the worse. Write your code with Murphy in mind. Anything that can go wrong, will go wrong at some point. Especially when relying on (global) variables that are defined at some distance from the code where they are used, so it's easy to not notice the problem until it's too late.
You're right Ivo.