最近更新到PHP 7.1,并开始出现以下错误
警告:第29行中遇到非数字值
这是第29行的样子
$sub_total += ($item['quantity'] * $product['price']);
在本地主机上工作正常.
你知道怎么撞击这是什么吗?
最近更新到PHP 7.1,并开始出现以下错误
警告:第29行中遇到非数字值
这是第29行的样子
$sub_total += ($item['quantity'] * $product['price']);
在本地主机上工作正常.
你知道怎么撞击这是什么吗?
在PHP7.1中,如果遇到非数值,似乎会发出警告.看这个link.
以下是与您收到的警告通知相关的部分:
无效时引入了新的E_警告和E_通知错误
我猜$item['quantity']或$product['price']都不包含数值,所以在try 相乘之前,请确保它们包含数值.在计算$sub_总额之前,可能会使用某种条件,例如:
<?php
if (is_numeric($item['quantity']) && is_numeric($product['price'])) {
$sub_total += ($item['quantity'] * $product['price']);
} else {
// do some error handling...
}