5
I had a question that I could not solve. Follow the codes of 3 files
Php user.
class Usuario{
//protected $nome;
public function getNome() {
return $this->nome;
}
public function setNome($nome){
$this->nome = $nome;
}
}
Pupil.php
class Aluno extends Usuario{
}
index php.
$aluno = new Aluno();
$aluno->setNome($_POST['nome']);
echo $aluno->getNome();
As you can see, the $name attribute is commented and the line $aluno->setNome($_POST['nome']);
returns the value of the field filled in the form. I found it strange, because I thought I had to see an indefinite variable message, or something like.
My question that remained was the following, as the name of the student prints on the screen normally if the attribute $nome
is commented?
The connections and other things are just right, I just didn’t put it all in so it wouldn’t get too big.
Does not solve the scope problem if the variable has not previously been initialized.
– Edilson