Fatal error: Unsupported operand types | PHP error

Asked

Viewed 2,514 times

0

Inside this Script, gives the following error:

Fatal error: Unsupported operand types in C: Easyphp-Devserver-14.1VC11 data localweb Administrating application holerites holerites.php on line 126

        if($r->totalProvento==NULL){
            #total a receber
            $totalProvento = "0.00";
            $totalDesconto = "0.00";
            $totalReceber = "0.00";
        } else { 
            #total a receber
            ----> 126 - $totalProvento = $r->totalProvento->totalProvento + $r->salario;
            $totalDesconto = $r->totalDesconto->totalDesconto;
            $totalReceber = $totalProvento - $totalDesconto;
        }
  • Some of them are empty?

  • Yes, the empty array may occur

  • cast to double, it must force null or '' to zero

  • 1

    Strings are not numbers, and numbers are not strings, that’s exactly what you did there, putting the 0.00 amid " "

  • I didn’t understand a thing..

  • What is this ? $r->totalProvento->totalProvento ?

  • That’s right ----> 126 ?

  • I’m just pointing out which line is coming wrong

Show 3 more comments

1 answer

0


You are doing your if wrong, because if you enter the first condition, you will not enter Else which is where the sum occurs a returns the typing error.

Try this:

$totalProvento = ($r->totalProvento==NULL ? 0.00 : ($r->totalProvento->totalProvento + $r->salario));
$totalDesconto = ($r->totalProvento==NULL ? 0.00 : $r->totalDesconto->totalDesconto);
$totalReceber = ($r->totalProvento==NULL ? 0.00 : ($totalProvento - $totalDesconto));

// ou

if($r->totalProvento==NULL){
    #total a receber
    $totalProvento = 0.00;
    $totalDesconto = 0.00;
    $totalReceber = 0.00;
}

$totalProvento = ($r->totalProvento->totalProvento + $r->salario);
$totalDesconto = $r->totalDesconto->totalDesconto;
$totalReceber = ($totalProvento - $totalDesconto);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.