-3

count(): Parameter must be an array or an object that implements Countable in C:\htdocs..\components\com_jcomments\tpl\joomspirit_theme\tpl_form.php

$customBBCodes = $this->getVar('comments-form-custombbcodes');
if (count($customBBCodes)) {
    foreach($customBBCodes as $code) {
        if ($code->button_enabled) {
            $k = 'custombbcode' . $code->id;
            $title = trim(JCommentsText::jsEscape($code->button_title));
            $text = empty($code->button_prompt) ? JText::_('BBCODE_HINT_ENTER_TEXT') : JText::_($code->button_prompt);
            $open_tag = $code->button_open_tag;
            $close_tag = $code->button_close_tag;
            $icon = $code->button_image;
            $css = $code->button_css;
        }
    }
}

I am running this script in my Joomla 3.0 application with PHP7.3 on Apache.

mickmackusa
  • 43,625
  • 12
  • 83
  • 136
saeed
  • 19
  • 1
  • 6
  • `var_dump($customBBCodes)` – u_mulder Jan 20 '19 at 11:38
  • So `$customBBCodes` is not as you expect an array or object. Check what `$this->getVar('comments-form-custombbcodes');` is returning – RiggsFolly Jan 20 '19 at 12:08
  • What exactly is the purpose of `if (count($customBBCodes)) {`? This seems totally unnecessary here. – Dharman Jan 20 '19 at 12:23
  • Since we don't know `$customBBCodes`'s data type or value, this question needs better diagnostic detail to be appropriately/accurately answered. Offering `is_array()` without knowing what the actual and expected range of data types are -- is premature. – mickmackusa Jan 31 '21 at 04:30
  • I expect a similar fate as this page: https://stackoverflow.com/q/51594817/2943403 – mickmackusa Jan 31 '21 at 04:37

1 Answers1

0

must add
if(is_array($customBBCodes)){

all change to

   `$customBBCodes = $this->getVar('comments-form-custombbcodes');
    if(is_array($customBBCodes)){
        if (count($customBBCodes)) {
            foreach($customBBCodes as $code) {
                if ($code->button_enabled) {
                    $k = 'custombbcode' . $code->id;
                    $title = trim(JCommentsText::jsEscape($code->button_title));
                    $text = empty($code->button_prompt) ? JText::_('BBCODE_HINT_ENTER_TEXT') : JText::_($code->button_prompt);
                    $open_tag = $code->button_open_tag;
                    $close_tag = $code->button_close_tag;
                    $icon = $code->button_image;
                    $css = $code->button_css;`                    
saeed
  • 19
  • 1
  • 6