This experimental program demonstrates what I think you're looking for.
<?php
// learn_obj_sess.php Learn About Objects and Sessions
// Copyright (c) 2001 ProjMan project. Author: Lyno Sullivan 3/26/01.
// This is free software and comes with ABSOLUTELY NO WARRANTY.
// Permission is granted to copy, distribute and/or modify this
// program under the terms of the GNU General Public License (GPL),
// Version 2 or later (http://www.gnu.org/copyleft/gpl.html).
// Projman Project https://sourceforge.net/projects/projman/
//*********************
// session initialize
//***********************
$sess_startup = FALSE;
if (!isset($S_sess_started))
{
error_reporting ( E_ALL );
session_start();
session_register('S_sess_started');
$sess_startup = TRUE;
$S_sess_started = TRUE;
}
//*********************
// start form ******
//*********************
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<head>
<title>learn_obj_sess.php Learn About Objects and Sessions</title>
</head>
<body>
<h1>learn_obj_sess.php Learn About Objects and Sessions</h1>
<p>
This program constitutes an experiment in creating a simple ProjMan
data persistence model. The program automatically rolls all properly
constructed objects out to session data while the form resides at the
client. When the form is submitted back to the server, the objects
are rolled into memory from session data.
<br>Request URI: <?php echo $REQUEST_URI; ?>
</p>
<form action="<?php echo $REQUEST_URI; ?>" method="post">
<input type="submit" value="Submit">
<?php
//*********************
// define objects **
//*********************
// This class is the basic class used throughout ProjMan. All the
// other objects inherit these basic variables and methods. This
// object is the foundation of the ProjMan session persistence data
// model. It standardizes the way that an object:
// . is stored in memory
// . collects updates from the user
// . is stored in session data when the session is out in user land
// . is relaoded from session data when the user submits a response
// . is edited against the user submission
// . presents syntactic error messages to the user
// . memory resources are freed when the object is destructed
class o_obj
{
var $obj_value; // the data value of the object
var $obj_persist; // Save object in session data
var $obj_errmsg; //
function o_obj() { ; }
function o_obj_destruct() { ; }
function o_obj // Constructor
(
$value = '',
$persist = TRUE
)
{
$this->obj_value = $value;
$this->obj_persist = $persist;
$this->obj_errmsg = '';
return(TRUE);
}
} // end of o_obj object definition
class o_play extends o_obj
{
var $play_cnt;
function o_play
(
$var = ''
)
{
$this->o_obj ("$var");
$this->play_cnt = 0;
return(TRUE);
}
} // end of o_play object definition
//********************************
// rollin session *************
//********************************
if ($sess_startup == TRUE)
echo "Session was initialized<br>";
//********************************
// initialize some objects ****
//********************************
if (!isset($myobj))
{
$myobj = new o_obj("myvalue");
$myplay = new o_play("myplayval");
echo "Initialize myobj and mplay<br>";
}
if (!isset($nosave))
{
$nosave = new o_play("nosaveval");
$nosave->obj_persist = FALSE;
echo "Initialize nosave<br>";
}
//********************************
// count times used ***********
//********************************
$myplay->play_cnt++; // proof -- this increments each Submit
$nosave->play_cnt++; // proof -- this stays 1 with each Submit
//********************************
// display classes, objects ***
//********************************
echo "-------------- Classes --------------<br>";
$classlist = get_declared_classes ();
foreach ($classlist as $class)
if (!strncmp ($class, "o_", 2)) // test for equal
{
echo "Class: $class<br>";
}
echo "<br>-------------- Variables ------------<br>";
$varlist = get_defined_vars ();
foreach ($varlist as $key => $var)
{
if (is_object ($var))
{
echo "------- Start Object ---------<br>";
$cl = get_class($var);
echo "Class: $cl<br>";
echo "[$key]<br>";
$arr = get_object_vars($var);
$register_it = FALSE;
while (list($prop, $val) = each($arr))
{
echo "$prop = $val";
if ($prop == 'play_cnt')
echo ' ----- the proof';
echo '<br>';
if ($prop == 'obj_persist' && $val == TRUE)
$register_it = TRUE;
}
//*************************
// session rollout *****
//*************************
if ($register_it == TRUE)
{
session_register("$key");
echo "[$key] -- regsitered<br>";
}
else
echo "[$key] -- <b>NOT</b> regsitered<br>";
echo "--------- End Object ---------<br>";
}
}
//********************************
// form footer ****************
//********************************
echo '</body>';
echo '';
?>