From cfe81ab2ac506a2f47f5aab517fc4e7926e28b6a Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 19 May 2023 16:05:52 +0200 Subject: [PATCH] fix: Call to a member function setAttribute() on int, #3402 (#3403) --- lib/html.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/html.php b/lib/html.php index 2553f3a8..ad3e6509 100644 --- a/lib/html.php +++ b/lib/html.php @@ -187,12 +187,18 @@ function defaultLinkTo($dom, $url) // Use long method names for compatibility with simple_html_dom and DOMDocument - foreach ($dom->getElementsByTagName('img') as $image) { - $image->setAttribute('src', urljoin($url, $image->getAttribute('src'))); + $images = $dom->getElementsByTagName('img'); + if (is_array($images)) { + foreach ($images as $image) { + $image->setAttribute('src', urljoin($url, $image->getAttribute('src'))); + } } - foreach ($dom->getElementsByTagName('a') as $anchor) { - $anchor->setAttribute('href', urljoin($url, $anchor->getAttribute('href'))); + $anchors = $dom->getElementsByTagName('a'); + if (is_array($anchors)) { + foreach ($anchors as $anchor) { + $anchor->setAttribute('href', urljoin($url, $anchor->getAttribute('href'))); + } } // Will never be true for DOMDocument