Hello all-
I have a page that, depending on what stage in the program the user is, loads various screens. So take the following code as an example:
here's our class:
class A
{
var $a;
function setVar($setToThis)
{
echo "setting property";
$this->a = $setToThis;
}
function getVar()
{
return $this->a;
}
}
and the corresponding code:
require_once("A.php");
if (!isset($obj))
$obj = new A;
if (!isset($_POST['isPosted']))
{
$obj->setVar('Property is set');
echo $obj->getVar() . "<br />\n"; // test to see if property is set
echo<<<myForm
<form action="test.php" method="post">
<input type="submit" name="isPosted">
</form>
myForm;
}
if (isset($_POST['isPosted']))
{
$thisTest = $obj->getVar();
echo "<p>property is: " . $thisTest . "</p>\n"; // only prints 'property is: '!
}
I know that the property is set because I can print out the contents right after I set it. But after the form is submitted $thisTest is now empty even though the object is still initialized and availalble to call. Regardless of how the form is posted, shouldn't the property of my object stay set? What am I missing?
Thanks,
a9
PS. I may be looking at this from too much of a Java perspective and PHP may not work this way- let me know!