slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Ignore unused variable with SplFileObject when setting it to NULL

kwebble opened this issue · comments

To close a file created with SplFileObject, the variable should be set to NULL. For example:

class X {
    public function wrt (
    ): void {
        $sfo = new SplFileObject('junk.txt', FopenMode::WRITE);
        $sfo->fwrite('Some text');

        // Close the file.
        $sfo = NULL;
    }
}

The line with $sfo = NULL; is flagged by SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable.

It would be nice if the rule could detect this situation and not trigger an error for it.

Is not possible that unset($sFo) will work too?