Wise Advice from a Signature

I was search­ing for a quick and easy way of renam­ing an array key with­out alter­ing the order of the array ele­ments, when I stum­bled upon this thread. While it didn’t help me accom­plish my goal, I did enjoy Mark Baker’s signature:

Turn on error reporting!

I’d say his esti­mate is low, and that it is more like 95% of PHP prob­lems can be resolved by turn­ing on error reporting.

I think part of the issue is that every­one rec­om­mends “for secu­rity” to turn off error report­ing on pro­duc­tion web­sites. That’s fine I sup­pose, but only if your site has some way of telling you it is bro­ken (e.g., an emailer that sends you error logs, an error mes­sage on the screen that you can see or some­one will email to you, etc..). Just hav­ing a log isn’t enough. It is unrea­son­able to expect some­one to waste time look­ing at an error log that should be empty. Spend 5 min­utes and write your­self a lit­tle script to email the error log to you (or search Google and find one that is already pre-built), set up a cron, and then fix your bugs when they come rolling in.

I think what dri­ves me even cra­zier is when peo­ple turn error report­ing off to hide “safe” errors/warnings (i.e., non-fatal), like unde­fined index, unde­fined vari­able, or dep­re­cated errors. The com­pany I work for recently hired a con­trac­tor to help get us up to speed on an open source appli­ca­tion. We turned on error report­ing, and sud­denly the app was spew­ing warn­ings left and right. Our contractor’s advice? Turn off error reporting.

But the error mes­sages are there for a rea­son. If PHP is telling you that you are try­ing to use a vari­able or index that isn’t there, then it doesn’t mat­ter if it isn’t a fatal error: your code is bro­ken. It is try­ing to do some­thing that doesn’t make any sense, and the code needs fixed. 99% of the time this is as easy as set­ting defaults on your vari­ables or adding a few isset()‘s into your code.

So please, for the sake of the chil­dren, turn on error reporting.

This entry was posted in Web Dev. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>