Deprecated function: Automatic conversion of false to array is deprecated

Created on 5 September 2022, almost 2 years ago
Updated 19 January 2023, over 1 year ago

Problem/Motivation

When using the "Paragraphs table" formatter with the PHP 8.1 version, the following error appears in the logs:

Deprecated function: Automatic conversion of false to array is deprecated
Drupal\paragraphs_table\Controller\AjaxController->getResults() 
(line 184 of /(...)/web/modules/contrib/paragraphs_table/src/Controller/AjaxController.php)

It's a PHP8.1 + Drupal 9.4.5 installation

Steps to reproduce

  1. Use a Drupal 9 + PHP 8.1 installation
  2. Create a paragraph
  3. Create a paragraph field in a content type
  4. Configure the paragraph field with the paragraph created earlier
  5. In manage view, configure the field created previously with the "Paragraphs table" formatter
  6. Create a node with the paragraph filled
  7. Access previously created node
  8. Go to the reports page (/admin/reports/dblog)

Proposed resolution

As I understand this problem is being caused by the variable, $data, which is intended to be an array being created as FALSE, so that if it is not filled it returns FALSE.

My proposal is to create the variable $data as an empty array and validate if the array is empty or not at the time of return. If empty, returns FALSE. If the array contains data returns the variable $data.

Referred Code

Example:

    $data = [];
    foreach ($entities as $delta => $entity) {
      $table_entity = $this->renderBuild->build($entity);
      $objectData = new \stdClass();
      foreach ($components as $field_name => $field) {
        ...
      $data[$delta] = $objectData;
    }
    return count($data) ? $data : FALSE;

Proposed resolution

Remaining tasks

None.

User interface changes

None.

API changes

None.

Data model changes

Node.

πŸ› Bug report
Status

Closed: duplicate

Version

1.8

Component

Code

Created by

πŸ‡΅πŸ‡ΉPortugal jrochate

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.69.0 2024