Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.
Boy, I hate admitting when I am wrong. But I am wrong.
You can have persistence as long as you make sure to include the class code in EVERY PHP script that will be using that object data. When you store an object to a session variable it stores only the object variable data but you still need to provide the class code to be able to use that data in other PHP scripts.
I always thought this was impossible but now that I know about it this opens up all kinds of new possabilities. Thanks guys for opening my blind little eyes.
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
<title>Test</title>
</head>
<body>
New page: retrieve the stored data from the object. <br><br>
<?php
class test
{
var $something;
function mytest($data)
{
$this->something = $data;
}
function gettest()
{
return $this->something;
}
}
$myobject = $_SESSION['myobject'];
echo "\$myobject->gettest() = " . $myobject->gettest();
?>
<br>
<a href="testsession.php">Click Me</a>
</body>
</html>
Hey this is great yepiii we are learning.. Good thread. I'm too testing my script as ev0l and others said. Lets reconstruct object in every page and see how the performance is. I can carry the ID in a session variable so no problem. Next if can lets dig in to this singleton pattern and find a way were we can use the object.. Wow today will be so much coding... lets rock..
Hmmm but i found out some thing wrong directly putting object to session variable. But i will check it in my server as well and update you guys. Hmmm thats why i did the serialization. Thanks guys.
Hey yep AKA Panama Jack, its working awesome. Auto serialization works. Thanks, seems we dont have to do the serialization when we put in to a session variable. Hmmm Now back to reconstruction.