- Always check that a variable is set if any possibility exists that it might not be, before trying to use it.
- Declare the default timezone when using server date/time variables. While it may assume correctly, it creates warnings to remind you to do so.
- Don't pass empty variables to be processed by methods when it is unnecessary to do so.
- Consider testing for NULL values and create procedures or breaks in loops for handling that.
Thursday, December 22, 2011
Account for Every Possible Eventuality
I spent a day this week working on a project which needed some serious housekeeping doing to it. While working adequately for the end user, it was filling our PHP error log with volumes of warnings, primarily associated with referencing unset indexes or variables. In my earlier programming days I was good about accounting for events which I expected to happen in the logical flow through my code, but I often neglected to account for the unexpected. Some of my housekeeping included: