Actually, this is already working. But it is a bad practice.
Normally you should do something like this:
class test {
private $abc;
public function foo() {
echo $this->abc;
}
public function getABC() {
return $this->abc;
}
public function setABC($abc) {
// You can also add some additionally checks
$this->abc = $abc;
}
}
Which makes:
$bar = new test;
$bar->setABC('abc');
$bar->foo();
Remember to make your class attributes ($abc) always private or protected. It's encapsulation that makes OOP so powerfull.
If you want to use dynamic variable names, so instead of $this->abc you want to set $this->cba you should use the magic methods __set and __get
More about magic methods can be found here:
http://php.net/manual/en/language.oop5.magic.php