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().