View Single Post
  #18  
Old 07-05-2019, 10:46 AM
 
Thomasb134 Thomasb134 is offline
 

X-Adept
  
Join Date: Apr 2007
Location: USA
Posts: 789
 

Default Re: altered carts OnSale mod for php 7+

That warning was suppressed in earlier PHP versions. But now PHP7.2+ has elevated the warning to encourage better coding practices.

The solution is to test the variable to confirm it is countable BEFORE counting it. It would be something like this:
Code:
$smarty->assign('wPidCount', (($sale['criteria']['wholesale'] instanceof Countable) && count(isset($sale['criteria']['wholesale'])) ? $sale['criteria']['wholesale'] : 0)+1);

This is just a coding example and may not work as-is. My example is just to give you a fundamental idea on how to fix it.

BTW, PHP7.3 introduced the is_countable() function as alternate way to do the "instanceof Countable" var test. Details here:
https://www.php.net/manual/en/function.is-countable.php

.
__________________
Thomas / USA
XCart V4.4.5 Gold
XCart Mobile V1.4.12
XCart X-PDF
XCart X-HotProducts
AlteredCart Checkout One (One Page Checkout)
BCSE Back In Stock
CFL Holiday Message
CFL System Message
Smack Digital (WebsiteCM) Remember Anon Carts
xcartmods Testimonials
xcartmods reCAPTCHA for X-Cart Classic
Unix, PHP 7.0 (patched 5.4).
MySQL 5.6
Reply With Quote