0
I created a fictitious example of a discount on a person’s salary, the code works, but two appear notices I listed below the code:
class Descontos{
public $salario;
public $inss;
public $salarioLiquido;
public function calcularPorcentagemINSS():float{
if($this->salario < 1693.62 ){
$this->inss = 8/100;
} else if( $this->salario > 1693.63 OR $this->salario < 2822.90 ) {
$this->inss = 9/100;
} else {
$this->inss = 11/100;
}
return $this->inss;
}
public function calcularValorINSS(){
return $this->inss * $this->salario;
}
public function calcularSalarioLiquido(){
return $this->salario - $this->calcularValorINSS();
}
}
# INSTÂNCIA DA CLASSE
$salario = new Descontos();
echo "Salário bruto: " . $salario->salario = 2000 . "<br/>";
echo "Porcentagem INSS: " . $salario->calcularPorcentagemINSS() * 100 . "% <br/>";
echo "Valor de desconto INSS: " . $salario->calcularValorINSS() . "<br/>";
echo "Salário Líquido: " . $salario->calcularSalarioLiquido();
Notices presented:
Notice: A non well Formed Numeric value encountered in C: xampp htdocs 18 - POO 06 - class.php on line 23
Notice: A non well Formed Numeric value encountered in C: xampp htdocs 18 - POO 06 - class.php on line 27
How can I fix them?
Thanks for the solution presented and for the tips. I started studying Object Oriented Programming today, in which cases you would advise me to use this style of programming?
– user132891
In those extremely complex, ie in PHP does not make sense in almost all cases. Actually, I don’t know how much use it is for me to say this because almost all the material you have out there is teaching OOP wrong.
– Maniero