There are certain “polite observations” that are mildly infuriating, and then there are polite observations that genuinely help. An example: over on Comic Book Herald, a reader recently sent me an email with a list of comic book events I’m missing. Not “Hey, I think it’d be cool if you added these,” but just “You’re missing x, y, and z. You nose-faced loser.” Ok, I added the loser bit, but the tone was pretty clearly dissatisfaction at not receiving a free thing.
Over here, though, I had a reader kindly jump in and alert me to a giant PHP warning gracing the header of davebuesing.com like the world’s techiest pimple. I had no idea, and was a bit startled to find the following warning for all to see:
Warning: Creating default object from empty value in /folder/specific/to/your/site/theme/admin-hooks.php on line 160. We’re all gonna die!
As a relative noob to php I found the above warning pretty distressing. I’ve dealt with warnings inside my WordPress admin before, but never so publicly. Adding a PHP warning to your blog blanner is a pretty bold declaration of cluelessness and hackability. “Hey guys, I’m great at internet stuff! Don’t mind the “doom is upon us” warning at the top of the blog!”
After a whole bunch of research, though, I was able to find a remarkably quick “solution.” I air-quote solution for reasons that will become apparent in a moment. For now, the answer:
Add “error_reporting(E_Error);” to your PHP file sending the warning
To add this little line of code, you just need to access “Editor” in WordPress, and pull open the PHP file referenced in your warning from there. I added the code after all the file notes and before the first If statement, and I have successfully removed my error from the home page.
Note: It’s pretty foolish to add stuff willy-nilly to your live PHP files in editor. Ideally you would test this out on a localhost first. Or you can be like me and live on the edge of tomorrow #cruiselife
Now, if you happen to know a little something about something, you’ll pretty quickly realize this is basically just a band-aid that hides the warning. Again, it’s not a solution to the PHP error, so much as it is the removal of error messages on your blog homepage.
As I said, this is the quickest possible way to just get that gunk off your blog. If you find that functionality is lacking, or that things on your site are broken, clearly you’ll need to explore the PHP error in more detail. Forum explanations of all this are very tricky, and usually pretty specific to the site facing the warning. I’d start with the likely source of your problem, your server’s recent upgrade of PHP that you ignored because surely nothing would go wrong.
In the meantime, enjoy the error free homepage!