Fatal error: Unsupported operand types | PHP error

0

Within this script, it gives the following error:

  

Fatal error: Unsupported operand types in   C: \ EasyPHP-DevServer-14.1VC11 \ data \ localweb \ Administer \ application \ views \ holerites \ holerites.php   online 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;
        }
    
asked by anonymous 06.10.2015 / 01:07

1 answer

0

You are doing your wrong if, because if you enter the first condition, you will not enter the else that is where the sum occurs and the typing error returns you.

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);
    
06.10.2015 / 19:21