I was under the impression that the following concept would work, but the new value of $foo isn’t passed between functions. What is the correct way to do this?
class doSomething
{
public $foo = "good";
public function changeFooAgain()
{
$this->foo = "best";
}
public function changeFoo()
{
$this->foo = "better";
}
public function getFoo()
{
$this->changeFoo();
$this->changeFooAgain();
return $this->foo;
}
}
$foo = new doSomething;
print $foo->getFoo();
I am under the impression that :
fooproperty is being accessed from each method.If I execute your code :
getFoo()method is executedchangeFoo()method is executed —foois nowbetterchangeFooAgain()method is executed —foois nowbestgetFoo()returns the current value of thefoopropertybest(which is the last value that was assigned to thefooproperty) gets displayed