Notices are Errors

One of my big pet peeves with WP plugins and themes is that so many of them trigger PHP notices and warnings by failing to check if array indices exist before referencing them, or checking if a file exists before including it, etc. It may seem trivial, but even if you don’t care about the the correctness of it, there are still tangible problems it will cause for users and other developers.

The most obvious one is that they can completely screw up the page layout, especially on a dev server running XDebug (which outputs the call stack and some other useful info). They can also screw up the page layout by outputting notices inside HTML tags, cause pages to crash when a notice forces PHP to send the page headers prematurely, and clutter up log files, making it harder to identify more serious issues.

It’s not uncommon for me to install a plugin on a dev server, see that the first 5-10 lines on the screen are notices/warnings, and immediately switch to a competing plugin. No matter how good the plugin is, it’s just not worth the frustration and annoyance. It also makes me seriously doubt if the developer paid any attention to other best practices (including ones related to security), if they aren’t even doing something as basic as checking notices.

A couple weeks ago I came across a thread on the WP.org support forums where several leading developers in the community argued in favor of the idea that notices are errors, and should be handled accordingly. That was encouraging to see, and hopefully that idea will start to gain a wider acceptance among other plugin and theme developers.

If you’re a developer,¬†you should always have WP_DEBUG on when working on a project, and then gracefully handle any errors, notices, or warnings that appear.

Leave a Reply

Your email address will not be published. Required fields are marked *