How to use the methods and attributes of classes in PHP?

Started to learn PLO from the perspective of PHP and stumbled at the first steps. What I actually wrong in this example?
<?php
 class ClassName
{
 var $myTestVar = 0;

 function readVar() {
 echo $this--->$myTestVar;
}
}

 $a = new ClassName();
$a->readVar();
?>

The validator says :
PHP Notice: Undefined variable: myTestVar in ~/.../test.php on line 13
PHP Fatal error: Cannot access empty property in ~/.../test.php on line 13

The problem in the code or the validator?

update...
<?php
 class ClassName
{
 public $myTestVar;

 public function __construct() 
{
 $this--->myTestVar = 0;
}

 function readVar() {
 echo $this->$myTestVar;
}
}

 $a = new ClassName();
$a->readVar();
?>

The outcome is the same.
September 26th 19 at 11:54
3 answers
September 26th 19 at 11:56
Solution
The extra $ instead:
echo $this->$myTestVar;
need
echo $this->myTestVar;
That's how it is xD
Thank you very much. - buck commented on September 26th 19 at 11:59
The problem was that to access the properties of the object without the $ before the name of the property, since $ is already before this. But in Your case, the interpreter was looking for a local variable $myTestVar in the method readVar() in order to substitute its value in the expression $this->$myTestVar as a variable name. I.e., such design can be used to access a property whose name is recorded in a variable. - Melyssa commented on September 26th 19 at 12:02
By the way I this maneuver will come in handy. But do not affect whether a challenge to the security if I use the parameters passed by the GET? - buck commented on September 26th 19 at 12:05
Necessarily affect. Everything that comes into the program from the user to check out. - Melyssa commented on September 26th 19 at 12:08
September 26th 19 at 11:58
Started to learn OOP model, do not write the class fields in the old style
var $myTestVar = 0;
write what you need
public|private|protected $myTestVar;
or make a static field, if necessary.

this is the same - var $myTestVar = 0; already makes it static, so $this->myTestVar is empty
If you want to specify a default value, write in the constructor
public function __construct() 
{
 $this->myTestVar = 0;
}
"already makes it static" - how? - buck commented on September 26th 19 at 12:01
Wrote demo code specially for the theme in the toaster.
public $myTestVar; and initialize the designer with the problem of space not move. In fact the problem and found in this situation. - Melyssa commented on September 26th 19 at 12:04
magic, what else - buck commented on September 26th 19 at 12:07
As far as I know, static fields in PHP are declared with the static keyword. That said, maybe something I don't know. - Melyssa commented on September 26th 19 at 12:10
description of the variable in the style var $asd - makes a class field and a normal field and static, because php allows you to call it in any context, but with curses. the function func() inside a class. - Melyssa commented on September 26th 19 at 12:13
Created a class A with a field $myVar is declared using var. Trying to apply to the static A::$myVar, get fatal error: "Fatal error: Access to undeclared static property: A::$myVar" - buck commented on September 26th 19 at 12:16
Fatal error - it's not just "a curse", the error this level terminates the script. - Shayna_Ondricka commented on September 26th 19 at 12:19
Probably you mixed up the properties/methods of a class (static) private/public. PHP Yes, the property or method declared without an access modifier are public by default (for compatibility with PHP4), in Java, such members of a class are considered private by default. - Melyssa commented on September 26th 19 at 12:22
September 26th 19 at 12:00
Bother to start to read the documentation. And this is documentation and not articles of John DOE. There is even in Russian-translated (what about the PLO), and there is a very nice revealed the foundations. So I advise you to connect to Wikipedia and read up on "encapsulation".

Find more questions by tags LinuxOOPPHP