<?php
class ClassName
{
var $myTestVar = 0;
function readVar() {
echo $this->$myTestVar;
}
}
$a = new ClassName();
$a->readVar();
?>
PHP Notice: Undefined variable: myTestVar in ~/.../test.php on line 13
PHP Fatal error: Cannot access empty property in ~/.../test.php on line 13
<?php
class ClassName
{
public $myTestVar;
public function __construct()
{
$this->myTestVar = 0;
}
function readVar() {
echo $this->$myTestVar;
}
}
$a = new ClassName();
$a->readVar();
?>
var $myTestVar = 0;
public|private|protected $myTestVar;
var $myTestVar = 0;
уже делает ее статической, поэтому $this->myTestVar пустуетpublic function __construct()
{
$this->myTestVar = 0;
}