Debugging PHP…

By Angsuman Chakraborty, Gaea News Network
Saturday, May 21, 2005

Today I made some changes to the blog site (using WordPress 1.5) to make the surrounding content (like most discussed articles, related articles etc.) highly context sensitive. Also I made the fonts bigger to improve readability.

They weren’t big changes, just added few methods and modified few. I tested them on Windows installation of WordPress running on Apache server. So far so good. Worked like a charm.

So naturally I just uploaded them to live server running Linux. And the site went down. Now I also had made some changes with the theme (again tested). So it was hard to pinpoint the problem. At one point I removed the plugin directory and the problem persisted. The problem was that the site wasn’t coming up at all. Changing the error settings in the configuration file didn’t help.

When renaming the plugin directory failed I assumed data corruption. So I re-installed WordPress from scratch. Then manually imported the tables, not many, in the new database. I disabled the plugins. Anyway to cut the long story short I finally nailed it down to the changes I made in the plugin. After further investigation with a test blog setup I found the culprit.

I had the following PHP code, which works fine on my Windows 2000:
$foobah = $wp_query->get_queried_object()->cat_ID
A variation like $foobah = ($wp_query->get_queried_object())->cat_ID is fine too.

However both crashes and burns on my Linux system.
The solution was:
$obj = $wp_query->get_queried_object();
$foobah = $obj->cat_ID;

And now it works on both systems!

Am I the only one who thinks this is asinine behavior?

BTW: In case you are wondering the above code in WordPress will fetch you the category_id when you are in a category ( is_category() ). Unfortunately I couldn’t find any documented functionality to provide me with this information.

The documented functions in WordPress are more geared towards UI. Many of them actually output the generated string, making them harder to maniulate.

In the process I removed Google Ad from the left navigation bar (except from front page) hopefully making the site faster. Also I found a documented (and legal) way to prevent Google Ad from occupying the space when it doesn’t have any relevant advertisement. From now Google Ad Space will be filled with content whenever ads are not available.

I also drastically reduced the number of plugins I use in this site. The only external plugins at this point is WP-HashCash (Additionally I use the Referrer Bouncer and No Follow plugins developed internally). It seems to be having some problems with recent wave of spammers.

Discussion
May 23, 2005: 10:12 am

> by the way what country are you from?
India - https://blog.taragana.com/index.php/about-me/

I am curious to know why you guessed Germany :)


thomas
May 22, 2005: 10:34 pm

by the way what country are you from? I am guessing you are in Germany but I could be wrong..

Tom

May 22, 2005: 9:50 pm

3-4 spams crept in. It could be that they were manually entered, in which case HashCash doesn’t help much.
I was in a hurry so I just deleted them. Next time, if it recurs, I will analyze.


thomas
May 22, 2005: 8:36 pm

Are you saying that hascash failed against a spam attack? uh oh..

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :