noverify icon indicating copy to clipboard operation
noverify copied to clipboard

Wrong 'unused' mark on variable used in closure 'use' clause

Open vbifial opened this issue 4 years ago • 0 comments

Code Example

<?php

class Sample {

    /**
     * @return string
     */
    function run()
    {
        $reference = 'x';
        $a = function () use (&$reference) {
            return $reference;
        };
        $reference = 'y';
        return $a();
    }
}

Actual Behavior

<critical> INFO    unused: Variable reference is unused (use $_ to ignore this inspection) at Sample.php:14
        $reference = 'y';
        ^^^^^^^^^^

Expected Behavior

No errors found

vbifial avatar Sep 15 '20 09:09 vbifial