coding-standard
coding-standard copied to clipboard
Ignore unused variable with SplFileObject when setting it to NULL
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?