I trying to learn the Class syntax for PHP and I have produced this simple example of setting a class variable and then getting it. It returns the error :
"$prop1 undefined variable "
Anyone know whats wrong? Thanks
Server php version 5.2.17
"$prop1 undefined variable "
Anyone know whats wrong? Thanks
Code:
class MyClass
{
public $prop1 = "I'm a class property!";
public function getProp1()
{
return $this->$prop1;
}
}
$obj = new MyClass;
echo $obj->getProp1();
Server php version 5.2.17
Last edited: