Re: [PHP4BETA] Sessions and Objects
[email protected] ("Dave")
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <[email protected]> |
: On Thu, 18 May 2000, Dave wrote:
: > I just started looking again at using objects in sessions and it appears
: > with the latest RC that object serialization does not support
serialization
: > of methods yet...not that I ever heard that it would..or not.
: >
: > I caught somewhere that since PHP serialization does support object
: > properties that if the class is defined before a session_start() that
you
: > should be able to have the entire object back...including methods...is
this
: > the case? or no?
I tried your example Andrei and the methods are not available, however the
properties are and retain the value of $a->b
<? // Page 1
# save session
include "foo.class.php";
session_start();
session_register("a");
$a = new foo;
$a->b = 10;
?><a href=page2.php>Page 2</a>
<? // Page 2
# restore session
include "foo.class.php";
session_start();
var_dump($a);
?><br><a href=page1.php>Page 1</a>
<? $a->p(); ?> // This prints Call to undefined function: p() in....
<? // foo.class.php
class foo {
var $a;
var $b;
var $c;
function foo() {
echo "foo()<BR>\n";flush();
$this->a = 1;
$this->b = "a";
$this->c = array("hallo");
}
function p() {
echo $this->a." ".strlen($this->b)." ".count($this->c)."<BR>\n";
$this->a++;
$this->b.="a";
$this->c[]="hallo";
}
}
?>
: Yes, it is possible. Example:
:
: <?
: # save session
: include "foo.class.php";
: session_start();
: session_register("a");
: $a = new foo;
: $a->bar = 10;
: ?>
:
: <?
: # restore session
: include "foo.class.php";
: session_start();
: var_dump($a);
: ?>
:
: The second piece of code should print out your class and the methods
: should be available.
:
: -Andrei
:
: The church is near but the road is icy;
: the bar is far away but I will walk carefully. -- Russian proverb
: