View Full Version : Problem with serialize

09-24-2002, 10:47 AM
I have serialized an object and "added" it in a cookie. when i try to unserialize the object to a variable and call the gettype function i get as output "boolean". This is the code for unserialize:


$connection = $HTTP_COOKIE_VARS['login'];
$oracle = unserialize($connection);
echo gettype($connection)."<BR>".gettype($oracle);

the output is:

The code for serializing the object is the following:


$connection = serialize($oracle);
if (setcookie("login", $connection)){
header("Location: search.php");

What is wrong with unserialize? I saw the manual of php and it didn't mention that returns a boolean!!!!!!! And why should return a boolean in the first placE?!?!?!?!?! Please help me with that :(

09-24-2002, 03:40 PM
theres nothing wrong with serialize, if you look again at the manual you will see

"Never use gettype() to test for a certain type"

instead use is_object or is_array etc , that said until we know exactly what kind of data you are serializing its hard to know...

if you mean a true class object then that class needs to be accessible wherever you try and use it i.e. the below example is useless unless the include('s_cart.class.php'); line is there

include 's_cart.class.php';
$scart = new s_cart();

so above if the session exists we reproduce our saved object , else we start a new one, again unless we include the s_cart class it wont work.

(the session data is saved by a method of c_cart like so
function save_as_sess(){