PHP8 Compatibility. ValueError: DOMDocument::loadHTML()

Created on 22 August 2022, over 2 years ago
Updated 14 August 2024, 4 months ago

Problem/Motivation

In pwa.module in implementation of hook_flush_caches cache_set used to set data from _pwa_serviceworker_file. In _pwa_fetch_offline_page_resources function if drupal_http_request return empty data this can cause an error "ValueError: DOMDocument::loadHTML(): Argument #1 ($source) must not be empty in DOMDocument->loadHTML()" after switching to PHP8 and trying to clear cache in pwa.module, line 250
According to https://www.php.net/manual/en/language.operators.errorcontrol.php:

"Prior to PHP 8.0.0, the error_reporting() called inside the custom error handler always returned 0 if the error was suppressed by the @ operator.
As of PHP 8.0.0, it returns the value E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR | E_PARSE."

and

"Prior to PHP 8.0.0, it was possible for the @ operator to disable critical errors that will terminate script execution. For example, prepending @ to a call of a function which did not exist, by being unavailable or mistyped, would cause the script to terminate with no indication as to why."

there is a need to add additional check for $response->data.

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

🇰🇿Kazakhstan Dmitrii_Zadorozhnyi

Live updates comments and jobs are added and updated live.
  • PHP 8.0

    The issue particularly affects sites running on PHP version 8.0.0 or later.

  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024