Merged
Conversation
The `static` keyword is generally tokenized as `T_STATIC`. However, in PHPCS 3.x, there was one exception - when `static` was used in an `instanceof static` expression, the `static` keyword was tokenized as `T_STRING`. As of PHPCS 4.0, this exception has been removed and `static` in `instanceof static` will now also be tokenized as `T_STATIC`. This commit removes the code handling the PHPCS 3.x exception.
…ners As of PHPCS 4.0, `T_USE` (for closures), `T_ISSET`, `T_UNSET`, `T_EMPTY`, `T_EVAL`, `T_EXIT` are parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.
…nthesis owners As of PHPCS 4.0, `T_USE` (for closures), `T_ISSET`, `T_UNSET`, `T_EMPTY`, `T_EVAL`, `T_EXIT` are parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.
…wners As of PHPCS 4.0, `T_USE` (for closures), `T_ISSET`, `T_UNSET`, `T_EMPTY`, `T_EVAL`, `T_EXIT` are parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.
As of PHPCS 4.0, `T_USE` (for closures), `T_ISSET`, `T_UNSET`, `T_EMPTY`, `T_EVAL`, `T_EXIT` are parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.
As of PHPCS 4.0, `T_USE` (for closures), `T_ISSET`, `T_UNSET`, `T_EMPTY`, `T_EVAL`, `T_EXIT` are parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.
As of PHPCS 4.0, `T_USE` (for closures), `T_ISSET`, `T_UNSET`, `T_EMPTY`, `T_EVAL`, `T_EXIT` are parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to skip over a `T_NS_SEPARATOR` token for a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaces names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaces names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaces names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This means we can remove some code which is no longer needed as, for instance, a namespace relative name `namespace\something` will no longer use the `T_NAMESPACE` token.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to skip over a `T_NS_SEPARATOR` token for a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a `T_STRING` token is a namespaced name, as if it were, it would be tokenized differently.
As of PHPCS 4.0, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check for a `T_NS_SEPARATOR` token for a fully qualified call to exit/die, as that will be tokenized as part of the `T_EXIT` token as of PHPCS 4.0.
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check for `T_NS_SEPARATOR` or `T_NAMESPACE` tokens when examining names. The `Collections::namespacedNameTokens()` token array contains the PHPCS cross-version compatible tokens, while the `Collections::nameTokens()` token array contains only the tokens we need to take into account for PHPCS 4.x.
fd41bc6 to
fea212a
Compare
Member
Author
|
Note: this PR needs an update of the branch protection. I'll sort that out after it has been approved. |
wimg
approved these changes
Nov 30, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
PHP 8.5 contains various new syntaxes for which support will only be added to PHP_CodeSniffer 4.0. To detect these with PHPCompatibility, we need to drop support for PHPCS 3.x.
Note: this PR is a best effort to remove PHPCS 3.x specific code, but there may well be additional simplifications which can be made.
Also see:
Changes
Composer: drop support for PHPCS < 4.0
4.x does not retokenize
statictoT_STRINGafterinstanceofClasses/NewLateStaticBinding: remove PHPCS 3.x compat code
The
statickeyword is generally tokenized asT_STATIC. However, in PHPCS 3.x, there was one exception - whenstaticwas used in aninstanceof staticexpression, thestatickeyword was tokenized asT_STRING.As of PHPCS 4.0, this exception has been removed and
staticininstanceof staticwill now also be tokenized asT_STATIC.This commit removes the code handling the PHPCS 3.x exception.
More tokens are parenthesis owners in PHPCS 4.x
As of PHPCS 4.0,
T_USE(for closures),T_ISSET,T_UNSET,T_EMPTY,T_EVAL,T_EXITare parenthesis owners, so we don't need to token walk to search for the parenthesis opener/closer anymore, we can just access the token stream array indexes directly.FunctionDeclarations/NewTrailingComma: more tokens are parenthesis owners
FunctionUse/ArgumentFunctionsReportCurrentValue: more tokens are parenthesis owners
LanguageConstructs/NewEmptyNonVariable: more tokens are parenthesis owners
Syntax/NewFirstClassCallables: more tokens are parenthesis owners
Syntax/NewFunctionCallTrailingComma: more tokens are parenthesis owners
Variables/ForbiddenThisUseContexts: more tokens are parenthesis owners
Namespaces names are now tokenized as per PHP 8.0+
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check if a
T_STRINGtoken is a namespaced name, as if it were, it would be tokenized differently.This also means we can remove some code which is no longer needed as, for instance, a namespace relative name
namespace\somethingwill no longer use theT_NAMESPACEtoken.AbstractFunctionCallParameterSniff: minor simplification
MiscHelper::isUseOfGlobalConstant(): minor simplification
TokenGroup::isNumber(): minor simplification
FunctionUse/ArgumentFunctionsReportCurrentValue: minor simplification
FunctionUse/ArgumentFunctionsUsage: minor simplification
FunctionUse/NewFunctions: minor simplification
FunctionUse/RemovedFunctions: minor simplification
InitialValue/NewConstantScalarExpressions: minor simplification
Keywords/ForbiddenNames: minor simplification
Numbers/RemovedHexadecimalNumericStrings: minor simplification
ParameterValues/NewPasswordAlgoConstantValues: minor simplification
Variables/RemovedIndirectModificationOfGlobals: minor simplification
Variables/RemovedImplodeFlexibleParamOrder: minor simplification
T_EXIT now includes the namespace separator (where applicable)
ParameterValues/NewExitAsFunctionCall: minor simplification
As of PHPCS 4.0, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check for a
T_NS_SEPARATORtoken for a fully qualified call to exit/die, as that will be tokenized as part of theT_EXITtoken as of PHPCS 4.0.Various sniffs: minor simplification
As of PHPCS, namespaced names use the tokenization as per PHP 8.0. This also means that we no longer need to check for
T_NS_SEPARATORorT_NAMESPACEtokens when examining names.The
Collections::namespacedNameTokens()token array contains the PHPCS cross-version compatible tokens, while theCollections::nameTokens()token array contains only the tokens we need to take into account for PHPCS 4.x.Various documentation updates for PHPCS < 4 version drop