[PHP] Re: objects in session

2004-03-16 Thread Justin Patrin
Marc Serra wrote:

Hi,

I got problem when i want to save object in session.

 

I got my first page when I create my object and save it to session:

 

?php

Require 'test.inc.php';

Session_start();

 

$test = new test();

$test-Load($_Get['id']);

$_SESSION['save'] = $test;

?

 

In my second page I want to retrieve my object

?php

 

Require 'test.inc.php';

Session_start();

echo get_class($_SESSION['test']);

?

 

When I do get_class($_SESSION['test']); I got the message
__PHP_Incomplete_Class instead of test
 

Can you explain me where I can have made an error.

 

What's going on here is that you haven't redefined your class for PHP in 
the second page. When PHP saves your object, it saves only its data, not 
its functions and such. Are you sure you're defining your object 
correctly? Have you tried instantiating a test() object in the second page?

--
paperCrane Justin Patrin
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP] Re: objects in session

2004-03-14 Thread Nick F
You can use serialize() to convert an object (or array) into
a string, and store that into the session.
To get back it's original value, use unserialize().
?PHP
$my = new stdClass;
$my-name = 'nick';
$my-comp = 'slow';
$store_this = serialize($my);
// $store_this has value:
// O:8:stdClass:2:{s:4:name;s:4:nick;s:4:comp;s:4:slow;}
$original = unserialize($store_this);
// now back to my object.
?
Hope that helps :)
---
Nick F
sevengraff.com
Marc Serra wrote:
Hi,

I got problem when i want to save object in session.

 

I got my first page when I create my object and save it to session:

 

?php

Require 'test.inc.php';

Session_start();

 

$test = new test();

$test-Load($_Get['id']);

$_SESSION['save'] = $test;

?

 

In my second page I want to retrieve my object

?php

 

Require 'test.inc.php';

Session_start();

echo get_class($_SESSION['test']);

?

 

When I do get_class($_SESSION['test']); I got the message
__PHP_Incomplete_Class instead of test
 

Can you explain me where I can have made an error.

 

Thx,

 

Marc.

 

 

 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php