0
ola I’m wanting to display my result of my calculator functionImc but this not going, could help me I’m kind of layman in php.
error that this giving when running the site: Notice: Undefined Property: Pessoa::$calcularImc in C: xampp htdocs pw1 class a_a 0608 exemploFormulario php classes Pessoa.php on line 69
Pessoa.php
<?php
class Pessoa
{
private $nome;
private $idade;
private $peso;
private $altura;
public function setNome($nome)
{
$this->nome = $nome;
}
public function setIdade($idade)
{
$this->idade = $idade;
}
public function setPeso($peso)
{
$this->peso = $peso;
}
public function setAltura($altura)
{
$this->altura = $altura;
}
public function getNome()
{
return $this->nome;
}
public function getIdade()
{
return $this->idade;
}
public function getPeso()
{
return $this->peso;
}
public function getAltura()
{
return $this->altura;
}
public function calcularImc($peso, $altura)
{
return $peso/($altura * $altura);
}
public function cadastrar($nome, $idade, $peso, $altura)
{
$this->nome = $nome;
$this->idade = $idade;
$this->peso = $peso;
$this->altura = $altura;
}
public function exibir()
{
return"<b>Nome</b>: $this->nome<br>
<b>Idade</b>: $this->idade<br>
<b>peso</b>: $this->peso<br>
<b>altura</b>: $this->altura<br>
<b>imc</b>: $this->calcularImc<br>";
}
}
?>
sistema.php
<?php
if (isset($_POST['pagina'])) {
include 'classes/pessoa.php';
$p = new Pessoa();
$p->cadastrar($_POST['nome'], $_POST['idade'], $_POST['peso'], $_POST['altura']);
echo "<div>".$p->exibir()."</div>";
}
else{
echo "teste";
}
echo '<br><br><a href="../index.php">Voltar<a>';
?>
You edited the question but did not give the feedback, It was error at the time of putting in the OS or was wrong even?
– Mauro Alexandre
I returned the value and it still didn’t work
– Adler Santos Rodrigues
this error appears : "Notice: Undefined Property: Pessoa::$calcularImc in C: xampp htdocs exemploFormulario php classes Pessoa.php on line 69" And line 69 is where this: <b>imc</b>: $this->calcularImc<br>";
– Adler Santos Rodrigues
Put the error in the article, it will be easier to view. The error is here: $this->calcularImc You are running as if it were a property, but it is actually a method. Switch to $this->calculator()
– Mauro Alexandre
I just did that, but is appearing the () as a result.
– Adler Santos Rodrigues
Try like this <b>imc</b>: ". $this->calcularImc()." <br>";
– Mauro Alexandre
tried and gave the error: Fatal error: Uncaught Argumentcounterror: Too few Arguments to Function Pessoa::calcularImc(), 0 passed in C: xampp htdocs pw1 exemploFormulario php classes Pessoa.php on line 69 and Exactly 2 expected in C:xampp htdocs pw1 class For exampleFormulario php classes Pessoa.php:49 Stack trace: #0 C: xampp htdocs exemploFormulario php classes Pessoa.php(69): Pessoa->calcularImc() #1 C: xampp htdocs exemploFormulario php system.php(9): Pessoa->exibir() #2 {main} thrown in C: xampp htdocs exemploFormulario php classes Pessoa.php on line 49
– Adler Santos Rodrigues
thank you very much for helping but I managed to resolve with the reply of the Oberto
– Adler Santos Rodrigues