我有我的代码有问题。类的对象不能转换int
我不明白这样的错误:
Notice: Object of class stdClass could not be converted to int in C:\wamp\www\Site\include\fonction_panier.php on line 136
我行136:
return $total + $total*$_SESSION['panier']['tva']/100;
这条线路是在这个函数:
function montantlGlobalTVA() {
$total = 0;
for ($i = 0; $i<count($_SESSION['panier']['libelleProduit']); $i++) {
$total += $_SESSION['panier']['qteProduit'][$i]*$_SESSION['panier']['prixProduit'][$i];
}
return $total + $total*$_SESSION['panier']['tva']/100;
}
TVA是在我的数据库:
$select = $db->query("SELECT tva FROM produits");
$tva = $select->fetch(PDO::FETCH_OBJ);
$_SESSION['panier']['tva']= $tva;
当我做了var_dump()
:
<td><?php echo var_dump($_SESSION['panier']['tva'])." %";?></td>
我得到这样的结果:
object(stdClass)[1] public 'tva' => string '18' (length=2)
这是说$ _SESSION ['panier'] ['tva']'不是一个整数,这意味着你不能用它做数学。回应它,看看它是什么。 –
你可以使用''(int)''例如''$ total + =(int)$ _SESSION ['panier'] ['qteProduit'] [$ i] *(int)$ _SESSION ['panier'] ['prixProduit'] [$ i];'' – alistaircol
可能[参考 - 这是什么错误在PHP中意味着什么?](http://stackoverflow.com/questions/12769982/reference-what-does-this-error-mean-in-php) – miken32