Skip to content

Variable reported as unused on an assignment by reference #305

Closed
@rodrigoaguilera

Description

@rodrigoaguilera

I have the following code

$wrapper_id = $field_id . '_wrapper';
if (!isset($form[$field_id]) && isset($form[$wrapper_id])) {
  $element = &$form[$wrapper_id][$field_id];
} else {
  $element = &$form[$field_id];
}
$element['test'] = 'test';

(Last line added to illustrate that the variable is indeed "used").

It reports that $element is an unused variable in the first line it appears.
If I initialize $element the phpcs warning is gone but it should be possible to declare a variable like that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions