I try to use a variable in each instance for a class.
My example class:
class test {
private static $gvalue;
function setValue($value)
{
$this->gvalue = $value;
}
function getValue()
{
return $this->gvalue;
}
}
Now I create to instances of this class "test" and print out some values.
$obj = new test();
$obj2 = new test();
echo "1: ";
echo $obj->getValue();
echo " / ";
echo $obj2->getValue();
$obj->setValue("green");
echo "<BR>2: ";
echo $obj->getValue();
echo "/";
echo $obj2->getValue();
My expectation was to get the following output:
1: / 2: green/green
But the result is:
1: / 2: green/
Did I understand something wrong? Or ist that not possible in PHP? Goal at the end. I would like to set some variables/arrays during the creation of an instance (__construc) and us that for every instance during the code (per user request).