Typed property must not be accessed before initialisation

Created on 31 March 2023, over 1 year ago

Problem/Motivation

I am getting the following error when trying to process a number of view results through vbo_export.

Error: Typed property Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase::$view must not be accessed before initialization in Drupal\vbo_export\Plugin\Action\VboExportBase->setHeader() (line 312 of /code/web/modules/contrib/vbo_export/src/Plugin/Action/VboExportBase.php)

When typed properties were introduced into classes in Php7.4, it became essential to initialise them before they were accessed. This is usually done in the class constructor, but it can be done by specifying a default value in the class where the property is defined.

The typed property protected ViewExecutable $view; in class \Drupal\views_bulk_operations\Action\ViewsBulkOperationsActionBase is not initialised in the constructor (of final class Drupal\vbo_export\Pugin\Action\VboExportXlsx nor its parents). This gives the potential for the error if the property is accessed before it is set, which is happening in my case.

Proposed resolution

To avoid this problem, it would be useful to assign a default value to the typed property in the class ViewsBulkOperationsActionBase where it is defined. This could be done with a statement like:
protected ?ViewExecutable $view = NULL;

Additional notes

This looks like it is related to the issue 🐛 VBO 4 doesn't process every selected node Fixed .

🐛 Bug report
Status

Active

Version

4.2

Component

Actions

Created by

🇳🇿New Zealand jlscott

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

Comments & Activities

  • Issue created by @jlscott
  • @jlscott opened merge request.
Production build 0.71.5 2024