Skip to content

Fix PHP 8.4 null deprecation warnings in class-delivery.php#1179

Merged
gabrielcld2 merged 1 commit into
developfrom
bugfix/php84-delivery-null-warnings
Jun 18, 2026
Merged

Fix PHP 8.4 null deprecation warnings in class-delivery.php#1179
gabrielcld2 merged 1 commit into
developfrom
bugfix/php84-delivery-null-warnings

Conversation

@utkarshcloudinary

@utkarshcloudinary utkarshcloudinary commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Issue

Reported on the WordPress.org support forum: PHP 8.4 deprecation warnings from class-delivery.php:

PHP Warning:  Undefined array key "src" in php/class-delivery.php on line 1569
PHP Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in php/class-delivery.php on line 1947
PHP Deprecated: strtok(): Passing null to parameter #1 ($string) of type string is deprecated in php/class-delivery.php on line 1952

Root cause

In get_tag_element(), the src attribute was dereferenced directly:

$raw_url = 'source' === $tag_element['tag'] && ! empty( $attributes['srcset'] ) ? $attributes['srcset'] : $attributes['src'];

When a parsed tag has no src attribute, this emits Undefined array key "src" and sets $raw_url to null. That null then flows into sanitize_url(), where strlen( $url ) and strtok( $url, '?' ) trigger the PHP 8.4 deprecation notices.

Fix

  • Default a missing src to an empty string (?? '') and bail early when there is no usable URL.
  • Guard sanitize_url() against non-string / empty input as a defensive measure.

QA

  1. On a PHP 8.4 site with the plugin active, render markup that contains tags without a src attribute (or otherwise empty source).
  2. Before the fix: Undefined array key "src" warning plus strlen() / strtok() null deprecations in the logs.
  3. After the fix: no warnings; delivery filtering continues to work for valid URLs.

When a parsed tag has no src attribute, get_tag_element() accessed
$attributes['src'] directly, emitting 'Undefined array key "src"' and
passing null downstream into sanitize_url(), which then triggered
'strlen(): Passing null' and 'strtok(): Passing null' deprecations on
PHP 8.4.

- Default missing src to an empty string and bail when no usable URL.
- Guard sanitize_url() against non-string/empty input.
@gabrielcld2 gabrielcld2 merged commit 6babc5a into develop Jun 18, 2026
8 checks passed
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.

4 participants