mrcodes

Hello guys, I have an issue: I'm getting this error message below on my script:W …

Tue 10 Apr, 2018 03:42 am

Hello guys, I have an issue: I'm getting this error message below on my script:


Warning: count(): Parameter must be an array or an object that implements Countable in /home/advaaxrv/test.pee.ng/models/Analytics.php on line 19

 lie 19

and this is the lines below:

12. public static function getData($link) {
13.    $analytics = new self;
14.    $data = $analytics::sel_table(self::$table)->find(['link_id' => $link->id]);
15.
16.    $analytics::$data = $data;
17.
18.    // TOTAL NUMBER OF VISITS
19.   $analytics->total_visits = count($data);
20.
21.    // LAST VISIT DATE
22.    $last_analytic_data = array_reverse($data);
23.    $analytics->last_visit = date("jS M, Y, h:i a", strtotime(array_shift($last_analytic_data)->date));
24.    
25.    return $analytics;
26.  }
It notice this works perfectly on my local server running PHP 7.1.9 but fails on my production server running PHP 7.2 and upon changing my production server from to 7.1.* it works well...


Is it that there's another way of calling the count function on Objects/Arrays in 7.2?

Comments

dhtml

Tue 10 Apr, 2018 05:09 am

Try adding this to line 14:

$data = (array) $data;

mrcodes

Tue 10 Apr, 2018 12:08 pm
dhtml wrote:

Try adding this to line 14:

$data = (array) $data;

Okay, that would be casting the object or string value to an array type right?

Thanks alot.