public $myVar="this is demo";
public function myTextdemo()
return $this->myVar; # the problem was here
$obj = new myClass();
echo $obj->myVar; # and here you wrote $obj->$myVar with an extra $
use return to output data from a function not echo and use $this inside the class functions, otherwise the declared property will not be considered and you will get an error like Undefined variable...