I have the following PHP code:
<?php
class Animal
{
private $nome;
public function getNome():string
{
return $this->nome;
}
public function setNome($value)
{
$this->nome=$value;
}
}
class Cachorro extends Animal
{
public function Andar()
{
echo $this->getNome() ." está andando."; //Essa linha funciona
echo "$this->getNome() está andando."; //Essa linha gera o erro: Notice: Undefined property: Dog::$getName in C:\xampp\htdocs\stackoverflow\question1\sample.php on line 27 () is walking.
}
}
$cao = new Cachorro();
$cao->setNome("Snoopy");
$cao->Andar();
?>
Why does it make a mistake when I do it?
echo $this->getNome() ." está andando."; //Essa linha funciona
echo "$this->getNome() está andando."; //Essa linha gera o erro: Notice: Undefined property: Dog::$getName in C:\xampp\htdocs\stackoverflow\question1\sample.php on line 27 () is walking.