Deprecated warning and foreach error in deferjs_js_alter() when installing DeferJS module on Drupal 10.3

Created on 27 April 2025, 13 days ago

Problem/Motivation

After installing and enabling the DeferJS module on a Drupal 10.3 site, the following warnings appear:

Deprecated Function Warning:

Deprecated function: explode(): Passing null to parameter #2 ($string) of type string is deprecated in deferjs_js_alter() (line 52 of modules/contrib/deferjs/deferjs.module).

Runtime Warning:
Warning: foreach() argument must be of type array|object, null given in deferjs_js_alter() (line 63 of modules/contrib/deferjs/deferjs.module).

This happens because explode() expects a string but is receiving null, and later foreach() expects an array or object but again receives null.

Steps to reproduce

Install and enable the DeferJS module on a Drupal 10.3 site.

Visit any page (frontend or admin).

Observe the warnings in the logs.

Proposed resolution

Add a check to ensure the value passed to explode() is not null.

Ensure the result is an array before running foreach().

📌 Task
Status

Active

Version

1.0

Component

Code

Created by

🇮🇳India Rohit Rana

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024