I was searching for a quick and easy way of renaming an array key without altering the order of the array elements, when I stumbled upon this thread. While it didn’t help me accomplish my goal, I did enjoy Mark Baker’s signature:
I’d say his estimate is low, and that it is more like 95% of PHP problems can be resolved by turning on error reporting.
I think part of the issue is that everyone recommends “for security” to turn off error reporting on production websites. That’s fine I suppose, but only if your site has some way of telling you it is broken (e.g., an emailer that sends you error logs, an error message on the screen that you can see or someone will email to you, etc..). Just having a log isn’t enough. It is unreasonable to expect someone to waste time looking at an error log that should be empty. Spend 5 minutes and write yourself a little 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 drives me even crazier is when people turn error reporting off to hide “safe” errors/warnings (i.e., non-fatal), like undefined index, undefined variable, or deprecated errors. The company I work for recently hired a contractor to help get us up to speed on an open source application. We turned on error reporting, and suddenly the app was spewing warnings left and right. Our contractor’s advice? Turn off error reporting.
But the error messages are there for a reason. If PHP is telling you that you are trying to use a variable or index that isn’t there, then it doesn’t matter if it isn’t a fatal error: your code is broken. It is trying to do something that doesn’t make any sense, and the code needs fixed. 99% of the time this is as easy as setting defaults on your variables or adding a few isset()‘s into your code.
So please, for the sake of the children, turn on error reporting.