0

I have an unsupported addon for concrete5 which is showing this error wehen upating php 7.1 to 7.2

i have not much knowledge about php and ask if somebody have an easy soltion for the code below.

<?php
$arr_tags = array();
foreach ($pages as $page) {
    $tags = $page->getAttribute('tags');
    if ($tags && count($tags)) {
        foreach ($tags as $tag) {
            $arr_tags[] = $tag;
        }
    }
}
$unique_tags = array_unique($arr_tags);
$keys = array_keys($unique_tags, '');
foreach ($keys as $k) {
    unset($unique_tags[$k]);
}
?>

count(): Parameter must be an array or an object that implements Countable

oliver
  • 1
  • Just replace the count() with is_array() – Dharman Oct 13 '19 at 11:36
  • thanks for the help, but unfortunately after this fix a lot of other errors appear. i am going to switch to another addon. one which is made for php 7.2 and obove. – oliver Oct 13 '19 at 18:21

1 Answers1

0

You could try casting your $tags variable as an array. (Take a look here: PHP: Count a stdClass object).

count($tags) would be count((array)$tags)
Dimger
  • 624
  • 4
  • 3