Saturday, March 24, 2007

Elseif

I like to optimise code after it is working to understand it better and therefore being able to maintain it more easily.

Yesterday, I copied some php code from PayPal's site. I noticed that in an if elseif endif there were statements in common in the if part and the elseif part. Naturally, I moved the statements to after the endif.

The result: thousands of emails from the program PayPal calls on my server when I make a payment (sandbox or otherwise)!

Why? Because the statements, that send an email, now were executed even when the if and the elseif conditions failed. :)

Conclusion: don't treat if elseif endif as if else endif!

No comments: