I have been going crazy for the past 3 days trying to debug the following cart application. The application works fine when running in localhost in Windows with PHP Version 5.3.1 But, when it runs in the Hostgator Linux server using PHP 5.2.11 it breaks, due to this error:
PHP Code:Fatal error: Call to a member function countItems() on a non-object in (*deleted path*)l/processCart2.php on line 109
Code clean of debug lines
switch statement :
initCar() :PHP Code:switch($action){
case "add":
if( !isset($_GET['item']) ) return;
$itemId = $_GET['item'];
$cart = initCar(); // While executing initCar() $_SESSION['cart'] is of type string, both when running in localhost and in the hostgator server.
/* Here, right after initCar() $_SESSION['cart'] in localhost is of type string in localhost but of type object in hostgator */
$prod = new Product($itemId, 1);
$cart->addProduct($prod);
/* $cart->countItems() works here */
echo ' cartcounting '.$cart->countItems();
$copy = $cart;
$copySerial = serialize($copy);
$_SESSION['cart'] = $copySerial;
/* $cart->countItems() does not work anymore when running in the Hostgator server, works in localhost */
echo ' cartcounting is now '.$cart->countItems();
include("drawCart.php");
return;
/* other cases for the switch here */
PHP Code:/* Returns Cart, new or unserialized */
function initCar(){
if(isset($_SESSION['cart'])){
$serializedCart = $_SESSION['cart'];
$cart = unserialize($serializedCart);
}
else{
$cart = new Cart;
}
return $cart;
}
Results of some tests I ran
For some reason the $cart instance of class Cart becomes a string at some point. This does not happen when running in localhost.
It also happens that after initCar() ends executing, $_SESSION['cart'] in localhost is of type string as it should. But, in the hostgator server $_SESSION['cart'] is of type object.
This is very strange as while initCar() executes $_SESSION['cart'] is of type string, both when running in localhost and in the hostgator server.PHP Code:/* localhost */
********* END initcar ********
$_SESSION["cart"] TYPE: string
Warning: get_class() expects parameter 1 to be object, string given in (*deleted path*)\processCart2.php on line 66
$_SESSION["cart"] CLASS:
/* Hostgator */
********* END initcar ********
$_SESSION["cart"] TYPE: object
$_SESSION["cart"] CLASS: Cart
PHP Code:/* Hostgator */
********* initCar() **********
$_SESSION["cart"] TYPE: string
$_SESSION["cart"] CLASS:
/* localhost */
********* initCar() **********
$_SESSION["cart"] TYPE: string
Warning: get_class() expects parameter 1 to be object, string given in (*path deleted*)\processCart2.php on line 34
$_SESSION["cart"] CLASS:







Bookmarks