Skip to content

Syntax makes EA complain about a possible Fatal error when in fact the array is ok #1976

@svenbergryen

Description

@svenbergryen

The following code causes EA to flag an Unsupported string offset operations error.

function uib_ui_form_alter(&$form): void {
  if ($form['#webform_id'] === 'feedback') {
    $result = 'blah';
  }
  $field = 'foo';
  $form[$field]['widget']['#default_value'] = $result;
}

It seems that line 2 in the snippet causes the reporting. If I remove that line, no error is shown.

Could provoke a PHP Fatal error (cannot use string offset as an array).

Subject Details
Plugin Php Inspections (EA Extended) or Php Inspections (EA Ultimate), which version
Language level e.g. PHP 7.2 (check project settings or composer.json)

Current behaviour

The code causes an potential error to be flagged.

Expected behaviour

Environment details

Information from Help - About dialog

Metadata

Metadata

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions