Skip to content

Commit f327dc3

Browse files
committed
AbstractArrayDeclarationSniff: improve the property reset
Unsetting a property leaves a property in a different PHP internal state then (re)setting it to an empty value. Most notably, an unset property triggers the magic `__set()`/`__get()` etc methods if available, and while this abstract doesn't declare those methods, a sniff implementing the abstract _may_. This change maintains the target behaviour (resetting the property values to save memory), while preventing side-effects from using `unset()` on these properties.
1 parent bb9d361 commit f327dc3

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

PHPCSUtils/AbstractSniffs/AbstractArrayDeclarationSniff.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ final public function process(File $phpcsFile, $stackPtr)
204204
$this->processArray($phpcsFile);
205205

206206
// Reset select properties between calls to this sniff to lower memory usage.
207-
unset($this->tokens, $this->arrayItems);
207+
$this->tokens = [];
208+
$this->arrayItems = [];
208209
}
209210

210211
/**

0 commit comments

Comments
 (0)