Skip to content

False-positive UndefinedVariable for static variable inside an anonymous function #277

Closed
@shvlv

Description

@shvlv

I stumbled upon the behavior when using the following code:

add_action('hook', static function (): void {
            static $providerId;
        });

It causes Variable $providerId is undefined. (VariableAnalysis.CodeAnalysis.VariableAnalysis.UndefinedVariable)

For my tests the minimum reproducible snippet was

$test = (function() {
            static $test;
        });

It seems round brackets do matter.

Thanks for maintaining a very useful library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions