Is it possible to make the following bar() method return "blue"?
class TestClass
{
public $var1 = "red";
public function foo() //returns red
{
return $this->var1;
}
public function bar() //still returns red
{
$this->var1 = "blue";
return $this->var1;
}
}
I know that class properties can't be variables, results of addition, etc. I read about overloading using __set and __get, however that seems to be geared towards totally dynamic properties.
$t = new TestClass; echo $t->bar();. How are you callingbar()? Since$var1is non-static, it is an instance property instead of a class property.