Warning: A non-numeric value encountered

后端 未结 18 1849
抹茶落季
抹茶落季 2020-11-22 06:15

Recently updated to PHP 7.1 and start getting following error

Warning: A non-numeric value encountered in on line 29

Here is wha

18条回答
  •  一个人的身影
    2020-11-22 06:30

    It seems that in PHP 7.1, a Warning will be emitted if a non-numeric value is encountered. See this link.

    Here is the relevant portion that pertains to the Warning notice you are getting:

    New E_WARNING and E_NOTICE errors have been introduced when invalid strings are coerced using operators expecting numbers or their assignment equivalents. An E_NOTICE is emitted when the string begins with a numeric value but contains trailing non-numeric characters, and an E_WARNING is emitted when the string does not contain a numeric value.

    I'm guessing either $item['quantity'] or $product['price'] does not contain a numeric value, so make sure that they do before trying to multiply them. Maybe use some sort of conditional before calculating the $sub_total, like so:

提交回复
热议问题