Skip to content

fix: prevent fatal error with list() assignment on missing images in PHP 8.2+#1035

Open
fuleinist wants to merge 1 commit intoCodeinwp:masterfrom
fuleinist:fix/issue-1034
Open

fix: prevent fatal error with list() assignment on missing images in PHP 8.2+#1035
fuleinist wants to merge 1 commit intoCodeinwp:masterfrom
fuleinist:fix/issue-1034

Conversation

@fuleinist
Copy link

All Submissions:

Changes proposed in this Pull Request:

Fix a fatal error that occurs in PHP 8.2+ when the lazyload placeholder feature is enabled and an image file is missing from the local uploads directory (e.g., offloaded to CDN or deleted).

The issue occurs in inc/lazyload_replacer.php at line 532 where list($width, $height) = $sizes is called, but `` can be false when the image file doesn't exist. PHP 8.2+ requires the argument to `list()` to be an array.

Closes #1034.

How to test the changes in this Pull Request:

  1. Use PHP 8.2 or higher
  2. Enable Lazyload with "Use placeholder" option
  3. Have an image that is offloaded to Optimole CDN
  4. Delete the local copy of the image
  5. View a post containing that image
  6. Before fix: Fatal error TypeError: list(): Argument #1 ($array) must be of type array, bool given
  7. After fix: No error; placeholder SVG uses fallback dimensions (100% width/height or dimensions from attachment metadata)

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

…PHP 8.2+

Fixes Codeinwp#1034

When an image file is missing (offloaded to CDN or deleted), the
get_svg_for() method would fail with a fatal error on PHP 8.2+ because
list() was being called on a boolean false value instead of an array.

This fix adds an is_array() check before the list() assignment to
gracefully handle missing images, allowing the fallback logic to
attempt getting dimensions from attachment metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fatal error with list() assignment in lazyload_replacer.php on PHP 8.2+ when handling missing images

1 participant