PHP 8.1 Deprecated function notices

Created on 19 October 2023, about 1 year ago
Updated 21 November 2023, about 1 year ago

Problem/Motivation

Visiting the form_builder has this Deprecated notices with PHP 8.1

Deprecated function: Automatic conversion of false to array is deprecated in form_builder_active_form() (line 274 of form_builder/form_builder.module).
Deprecated function: Drupal\form_builder\FormBase implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in require_once() (line 5 of form_builder/src/FormBase.php).
Deprecated function: Drupal\form_builder_webform\Form implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in require_once() (line 7 of /form_builder/modules/webform/src/Form.php).

Steps to reproduce

  1. Use PHP 8.1
  2. Install form_builder and webform
  3. Visit form_builder interface on a new or existing webform.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

RTBC

Version

2.0

Component

Form Builder Core

Created by

🇨🇦Canada joelpittet Vancouver

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.

  • PHP 8.2

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

Sign in to follow issues

Comments & Activities

  • Issue created by @joelpittet
  • Assigned to Shreya_98
  • @shreya_th opened merge request.
  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • 🇮🇳India Shreya_98

    Hi @joelpittet,
    I have fixed this issue and also created MR for this . kindly review the changes.

  • 🇨🇦Canada joelpittet Vancouver

    @Shreya_th thanks that looks like it would solve my problem. The thing you may want to consider is that since this is Drupal 7 project it would be good to not push to a version of PHP without providing BC for older versions.

    Good news is that this module already has a PHP 7.0 requirement so short array syntax is in play.

    So my suggestion would be to leave the interface as it suggests you can do:

    FormBase implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in require_once() (line 5 of form_builder/src/FormBase.php).

    I think that means you could keep the interface as long as you implement the new methods. This is what they did in this patch for reference:
    https://www.drupal.org/project/views_ajax_get/issues/3294688 🐛 Implements the Serializable interface, which is deprecated. RTBC

  • 🇨🇦Canada joelpittet Vancouver

    #5 might also mean removing some of the typehints for params and return types

  • Status changed to Needs work about 1 year ago
  • 🇨🇦Canada joelpittet Vancouver

    After testing the fix there is also these issues:

    
        Warning: Undefined property: Drupal\form_builder_webform\Form::$elements in Drupal\form_builder_webform\Form->__serialize() (line 177 of form_builder/modules/webform/src/Form.php).
        Warning: Undefined property: Drupal\form_builder_webform\Form::$elementParents in Drupal\form_builder_webform\Form->__serialize() (line 178 of form_builder/modules/webform/src/Form.php).
        Warning: Undefined property: Drupal\form_builder_webform\Form::$elements in Drupal\form_builder_webform\Form->__serialize() (line 177 of form_builder/modules/webform/src/Form.php).
        Warning: Undefined property: Drupal\form_builder_webform\Form::$elementParents in Drupal\form_builder_webform\Form->__serialize() (line 178 of form_builder/modules/webform/src/Form.php).
    
    

    Which seem to be related to the serialize changes.

  • Status changed to Needs review about 1 year ago
  • 🇨🇦Canada joelpittet Vancouver

    I pushed the changes I proposed but left the type hinting as it was in 7.4 and should help with potential signature errors.

  • Status changed to RTBC about 1 year ago
  • 🇩🇪Germany Anybody Porta Westfalica

    Just ran into this with PHP 8.2. Thanks for the fixes @joelpittet and @Shreya_th!

Production build 0.71.5 2024