-
-
Notifications
You must be signed in to change notification settings - Fork 89
Description
Repost from squizlabs/PHP_CodeSniffer#3115:
The
statickeyword in PHP is used for a number of different things:
- Static properties
- Static methods
- Static closures and arrow functions
- Static variables
- Late static binding
Now, for all these uses, the token is tokenized as
T_STATIC, with one exception: late static binding in combination with theinstanceofoperator.This defies the principle of least astonishment as both
selfandparentin combination withinstanceofare tokenized asT_SELFandT_PARENTrespectively.I've been caught out by this a couple of times already and I imagine that others have too, or if they haven't, that sniffs may be throwing false positives/negatives because of it.
It's not completely clear to me why this very specific exception was put in place, but I'd like to propose to remove this exception in PHPCS 4.x and let the
statickeyword be tokenized asT_STATICwhen preceded byinstanceof.Based on a history search, it looks to have been put in place in response to PEAR#19726.
In my opinion, that issue should have been fixed in the sniff code for theSquiz.WhiteSpace.ScopeKeywordSpacingsniff, not in the Tokenizer, same as is done in the sniff with other typical late static binding occurrences.Code sample
if ($geometry instanceof static) { echo 'foo'; }
staticin the above code sample is tokenized asT_STRING, notT_STATIC.