I am trying to build my first PHP class, and have encountered some strange behavior, which I have distilled into the following test class:
class TestClass {
var $var1 = '';
var $var2 = '';
var $var3 = '';
function TestClass($var1X, $var2X, $var3X) {
$this->$var1 = $var1X;
$this->$var2 = $var2X;
$this->$var3 = $var3X;
}
function getVar1() {
return $this->$var1;
}
function getVar2() {
return $this->$var2;
}
function getVar3() {
return $this->$var3;
}
function output() {
echo $this->$var1.'<br>';
echo $this->$var2.'<br>';
echo $this->$var3.'<br>';
echo '<br>';
echo $this->getVar1().'<br>';
echo $this->getVar2().'<br>';
echo $this->getVar3().'<br>';
}
}
When I execute the following code:
$test = new TestClass('steve', 'was', 'here');
$test->output();
I get the following output:
here
here
here
here
here
here
I have looked at a number of PHP class examples, and am pretty sure I am following the rules, but there must be some simple thing I'm missing.
Thanks,
Steve C.