Skip to content

Global variable falsely reported as never used #310

@cedric-anne

Description

@cedric-anne

Describe the bug
If inside a given context, e.g. a function, a global variable is set but never read, it is falsely reported as never used.

Describe the eclipse environment
Eclipse 2025-06
PDT 8.2

Describe your system

  • OS: ubuntu
  • Version 24.04

To Reproduce
2 warnings will be reported for the following code snippet:

  • Variable '$A' is never used on line 9
  • Variable '$C' is never used on line 9
<?php

namespace Foo;

class Bar
{
    public function doSomethingWithGlobals(): void
    {
        global $A, $B, $C;

        $A = new Bar();

        if ($B) {
            echo "azerty";
        }
    }
}

Expected behavior
The variable $A should not be considered as never used. Indeed it is a reference to the $A variable declared in the global scope and changing its value here has an impact outside the current context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions