PHP Code

Fixing a very common bug in !JoomlaComment

Create beautiful Joomla websites with a flexible layout from

On one of my sites running Joomla I wanted users to be able to comment on articles. I had akoComments installed, but I found it lacking. It wouldn't tell me which article was commented on! SO I upgraded to !JoomlaComment, which has lots of great features; like AJAX posting and replying capabilities. However, upon installing !JoomlaComment 2.4 final, right away I found a bug. One every page I was getting the following error:

Warning: Invalid argument supplied for foreach() in /home/username/public_html/components/com_comment/joscomment/properties.php on line 160

The problem was that it was trying to access the UserList array, without first checking if it there was anything there! I believe this was caused by the fact that I wasn't using Community Builder component. So I added a line to check first if there is a value for the UserList array, and prevent passing an empty array.

So open the properties.php file, and edit the lines 152-169 to look like this:

   function loadProfiles()
        global $database;
        $database->setQuery('SELECT #__users.username, #__comprofiler.user_id,
        #__comprofiler.avatar FROM #__users, #__comprofiler
        WHERE = #__comprofiler.user_id');
        $userList = $database->loadAssocList();
        $this->_profiles = array();
        //add this line
        //add the above line
        foreach ($userList as $item) {
            if ($this->_avatar) $this->_profiles[$item['username']]['avatar'] = $item['avatar'];
            else $this->_profiles[$item['username']]['avatar'] = false;
            if ($this->_profile) $this->_profiles[$item['username']]['id'] = $item['user_id'];
            else $this->_profiles[$item['username']]['id'] = false;
        //add this curly bracket
        //add the above curly bracket

Create beautiful Joomla websites with a flexible layout from


Leave a Reply

Your email address will not be published. Required fields are marked *

To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image