__PHP_Incomplete_Class
Tuesday, March 10th, 2009I stumbled across a brilliant bug today. I’ve been building an eCommerce site for a client, and had written a whole bunch of code that works flawlessly on my development server. However, as soon as I deployed to the production server, things went a bit Pete Tong.
Object of class __PHP_Incomplete_Class could not be converted to string
You can Google this phrase and find a million (approx) results for this, and it’s generally caused by people storing objects in a session variable, but not including the class definition before the session_start() statement. However, I was not doing this. I’m doing:
define("SESSION_CART", "cart");
$_SESSION[SESSION_CART] = serialize($cart);
After many hours of trying everything I could think of, tearing (what’s left) of my hair out, and generally throwing a programming tantrum, I finally resorted to the last ditch solution: renaming the variable to something stupid. Using this code fixed the problem:
define("SESSION_CART", "underpants");
$_SESSION[SESSION_CART] = serialize($cart);
So why should the name of a session variable make so much of a difference? I can only presume that the issue is caused by some third party shopping cart add-on software that’s hijacking the production server’s PHP configuration.