Deprecated Function: explode()

Created on 28 October 2024, about 2 months ago

Problem/Motivation

The module encounters a PHP deprecation warning and causes an error on the configuration page when running on newer PHP versions. This is due to the `explode()` function being called with a `null` value as the second parameter in the `js_confirm_pop_up_form_alter()` function. If `$form_ids` is empty or `null`, `explode(',', $form_ids)` triggers a warning because `explode()` expects a valid string.

Steps to reproduce

1. Install the module on a Drupal 7 site running the latest PHP version.
2. Navigate to Configuration > User Interface > JS Confirm Pop Up Settings.
3. The configuration page shows a deprecation error due to the `explode()` function being called on a `null` value when `$form_ids` is empty or unset.

Proposed resolution

Update the `js_confirm_pop_up_form_alter()` function to handle cases where `$form_ids` is `null` or empty. Modify the line to ensure `$form_ids_arr` is assigned an empty array when `$form_ids` is not a valid string:

Replace:

$form_ids_arr = explode(',', $form_ids);

With:

$form_ids_arr = !empty($form_ids) ? explode(',', $form_ids) : [];

This prevents errors and warnings when `$form_ids` is empty or `null`.

Remaining tasks

  • Review and test the patch to confirm it resolves the deprecation warning and configuration page error.
  • Document the fix and update the module's change log if applicable.

User interface changes

No user interface changes are introduced by this fix.

API changes

No API changes are introduced by this fix.

Data model changes

No data model changes are introduced by this fix.

🐛 Bug report
Status

Needs review

Version

1.3

Component

Code

Created by

🇵🇰Pakistan a_z_official

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

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

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024