jmcameron / attachments

Attachments Extension for Joomla 3, 4, and 5
GNU General Public License v3.0
12 stars 19 forks source link

php8 Warnings in Frontend #30

Open st-anton opened 2 years ago

st-anton commented 2 years ago

On some pages (I don't know the reason), there are warnings in the page on top of the content: `Warning: Undefined array key 0 in \plugins\attachments\attachments_for_content\attachments_for_content.php on line 827

Warning: Attempt to read property "created_by" on null in \plugins\attachments\attachments_for_content\attachments_for_content.php on line 827

Warning: Undefined array key 0 in \plugins\attachments\attachments_for_content\attachments_for_content.php on line 828

Warning: Attempt to read property "catid" on null in \plugins\attachments\attachments_for_content\attachments_for_content.php on line 828`

Kimball31 commented 1 year ago

Here's what I did to fix that PHP warning:

Change \plugins\attachments\attachments_for_content\attachments_for_content.php on lines 826-828:

            // See if the options apply to this article
            $created_by = (int) $attachments[0]->created_by;
            $catid      = (int) $attachments[0]->catid;

This this:

            // See if the options apply to this article 
            // (Revised for PHP7)
            if(is_object($attachments))
            {
                $created_by = (int) $attachments[0]->created_by;
                $catid      = (int) $attachments[0]->catid;
            }
            else
            {
                             $created_by = false;
                             $catid      = false;
            }
JLTRY commented 1 month ago

please use last version available for Joomla 4.x Joomla 5.x https://github.com/jmcameron/attachments/releases/tag/v4.0.1