Hello guys

this is the first time I see this message while i'm trying to register a new account:
the message : __php_incomplete_class could not be converted to string

I try var_dumb($_SESSION) and i get this:
object(__PHP_Incomplete_Class)[1]
public '__PHP_Incomplete_Class_Name' => string 'Customer' (length=8)
public 'id' => string '3' (length=1)
public 'firstName' => null
public 'lastName' => null
public 'email' => null
public 'balance' => int 0
public 'message' => string '' (length=0)
public 'password' => null
public 'address' => null

the code:

 public static function getCartId()
    {
        $dbh = mySqlDatabase::getConnectionObject();
        // if customer is logged in
        if (isset($_SESSION['customerId']) && !empty($_SESSION['customerId'])) {
            $customerId = $_SESSION['customerId'];
            $sql = "SELECT id FROM shoppingcarts WHERE customerId = :id AND isCompleted = 0";
            $stmt = $dbh->prepare($sql);
            $stmt->bindParam(':id', $customerId, PDO::PARAM_INT);
            $stmt->execute();
            $result = $stmt->fetchColumn();
            if ($stmt->rowCount() == 0) {
                // if there's a cart but not completed
                $sql = "INSERT INTO shoppingcarts(customerId, isCompleted, isShipped) VALUES ($customerId, 0, 0)";
                $stmt = $dbh->prepare($sql);
                $stmt->execute();
                $result = $dbh->lastInsertId();
                return $result;
            } else return $result;
        } else {
            // if customer is guest
            if (isset($_COOKIE['trace']) && !empty($_COOKIE['trace'])) {
                $shoppingCartId = $_COOKIE['trace'];
                return $shoppingCartId;
            } else {
                // user not logged in in and have no cookie
                $sql = "INSERT INTO shoppingcarts(customerId, isCompleted, isShipped) VALUES (1,0 ,0 )";
                $stmt = $dbh->prepare($sql);
                $stmt->execute();
                $result = $dbh->lastInsertId();
                setcookie('trace', $result, time() + 3 * 30 * 24 * 60 * 60);
                return $result;
            }
        }
    }

Recommended Answers

All 2 Replies

I don't understand the need of storing an instance of an object into a session. There are many ways in finding out if an instance of an object is present. There are singleton, factory, and instanceof PHP function that can be utilized. It does not take much to use them.

Can somebody please explain why is this indispensable?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.