Ss is possible, to access class properties inside this class methods without using “$this”, like in C++?
Small example:
class MyClass
{
protected $foo = 'abc';
protected $bar = 'dca';
public function __construct()
{
$foo = 'Hello';
$bar = 'World!';
}
public function display()
{
echo $foo . ' ' . $bar;
}
}
$MyObject = new MyClass();
$MyObject->display();
In result, I have notices about undefined variables.
But I’ld like to be sure – is it possible, or not?
No. It is not. In PHP, you have to use the
$this->syntax to access instance variables.