<?php
#
file sessiontest.php
#
class subObject {
var $stuff = "foo";
function subObject($stuff)
{
$this->stuff=$stuff;
}
}
class bigObject {
var $bigstuff = "foo";
var $subobjects = array();
function bigObject($junk)
{
foreach($junk as $lump) {
$this->subobjects[$lump] = new subObject($lump);
}
}
function next_subObject()
{
next($this->subobjects); #this should have some boundaries but its ok for the example
}
}
$act=$GET['act'];
switch($act) {
case "start":
$crap = array("foo","bar","buzz","eek","bazz");
$OBJECT=new bigObject($crap);
session_register('OBJECT');
$first = key($OBJECT->subobjects);
$OBJECT->next_subObject();
$second = key($OBJECT->subobjects);
$SESSION['OBJECT'] = $OBJECT;
Header("Location: sessiontest.php?act=last&first=$first&second=$second\r\n\r\n");
break;
case "last":
session_register('OBJECT');
$first=$_GET['first'];
$second=$_GET['second'];
$OBJECT=$_SESSION['OBJECT'];
$key=key($OBJECT->subobjects);
echo "first is $first, second is $second, key is $key";
exit;
break;
}
?>
This is the output I get:
first is foo, second is bar, key is foo
OK, so you call sessiontest.php?act=start
It creates the object and puts some junk in it. You get the key, which you would expect to be the first one. You call next. You get the key which you would expect to be the second one. You store the object . You go off to a new page fetch, which is the other case. You retrieve the object, which should be just as you left it, i.e. on the second key. The keys from the previous page are as expected. But when you print out all three keys, it's back to square one. It forgot about the next.