Upgrading squizlabs/php_codesniffer 2 to 3
Breaking2.9.2 → 3.13.6Breaking40Security8Platform3Deprecated36New179Changed313Fixed639Other55
SecurityHighFixes a security issue where the Gitblame, Hgblame or Svnblame reports could execute attacker-controlled shell commands for files with shell metacharacters in their names.GHSA-hmqg-cxww-wqhq · CVE-2026-67434 ↗
BreakingUpgrade verdict
39 breaking changes and 3 platform requirement changes and 7 security fixes.
In plain terms
- If you installed PHP_CodeSniffer with PEAR, you must switch to another installation method. The PEAR sniffs are unaffected.
- You can no longer install PHPCS through PEAR; use Composer or the PHAR files instead.
- Spacing around assignment operators inside function calls is no longer checked by this sniff; use Squiz.WhiteSpace.OperatorSpacing instead.
- Squiz.ControlStructures.ForLoopDeclaration improves whitespace, closure and empty expression support and removes the SpacingAfterSecondNoThird error code.
Must act Top 5 of 85 that need code or config changes
squizlabs/php_codesniffer publishes an official migration guide for version 3. It covers more than the release notes do.
Migration guide ↗PHP requirement changed in 3.0.0a1: >=5.1.2 → >=5.4.0.
What you must change
Breaking39
Installation of PHP_CodeSniffer via PEAR is no longer supported.
Removes support for installation via PEAR.
Generic.Functions.FunctionCallArgumentSpacing no longer checks spacing around assignment operators inside function calls.
Generic.Functions.FunctionCallArgumentSpacingSquiz.WhiteSpace.OperatorSpacingNoSpaceBeforeEqualsNoSpaceAfterEqualsNoSpaceBeforeNoSpaceAfterSquiz.ControlStructures.ForLoopDeclaration improves whitespace, closure and empty expression support and removes the SpacingAfterSecondNoThird error code.
Squiz.ControlStructures.ForLoopDeclarationSpacingAfterSecondNoThirdSquiz.Objects.ObjectMemberComma.Missing is renamed to Squiz.Objects.ObjectMemberComma.Found.
Squiz.Objects.ObjectMemberComma.MissingSquiz.Objects.ObjectMemberComma.FoundRemoves Squiz.PHP.DisallowObEndFlush from the Squiz standard.
Squiz.PHP.DisallowObEndFlushRemoves Squiz.PHP.ForbiddenFunctions from the Squiz standard, replaced by Generic.PHP.ForbiddenFunctions with different error codes.
Squiz.PHP.ForbiddenFunctionsGeneric.PHP.ForbiddenFunctionsforbiddenFunctionsRemoves the SpacingAfterOpenHint error message, replaced by the existing SpacingAfterOpen message.
SpacingAfterOpenHintSpacingAfterOpenRemoves the is_closure index from the return value of File::getMethodProperties().
File::getMethodProperties()is_closureT_FUNCTIONT_CLOSURERemoves the File::isAnonymousFunction() method.
File::isAnonymousFunction()T_FUNCTIONT_CLOSURERemoves the indent property of PEAR.Classes.ClassDeclaration; the sniff now only ensures the brace aligns with the class keyword.
PEAR.Classes.ClassDeclarationindentAdds support for ES6 method declarations without the function keyword, now tokenized as T_FUNCTION; custom JS sniffs listening for T_FUNCTION can no longer assume the token is the word "function".
T_FUNCTION$phpcsFile->getDeclarationName($stackPtr)PHPCBF no longer uses patch, always overwrites files, and the --no-patch option has been removed.
--no-patchRemoves the included PHPCS standard; all rules now live in the phpcs.xml.dist file.
phpcs.xml.distRemoves the included SVN pre-commit hook; version control hooks will no longer be maintained in the project.
Incorrectly set inline properties in test case files are silently ignored again, removing the
Internal.PropertyDoesNotExist error code.Internal.PropertyDoesNotExistCommon::getSniffCode() now throws InvalidArgumentException when passed an invalid $sniffClass.
Common::getSniffCode()InvalidArgumentExceptionSquiz.ControlStructures.ForEachLoopDeclaration replaces the SpacingAfterOpen error code with the pre-existing SpaceAfterOpen code.
Squiz.ControlStructures.ForEachLoopDeclarationSpacingAfterOpenSpaceAfterOpenThe squizlabs/PHP_CodeSniffer repository is abandoned; PHPCSStandards/PHP_CodeSniffer continues the project.
PHIVE users may need to clear the PHIVE URL cache and update the package URL to phars.phpcodesniffer.com.
Users downloading PHAR files with curl or wget must update the download URL to phars.phpcodesniffer.com.
phpcsphpcbfGit clone users must update the clone address to the PHPCSStandards repository.
Invalid sniff properties set for individual sniffs now result in an error and halt PHPCS execution.
The third parameter for Ruleset::setSniffProperty() now expects an array, with existing code throwing a deprecation error.
Ruleset::setSniffProperty()Changes the value of the T_FN_ARROW token from "T_FN_ARROW" to "PHPCS_T_FN_ARROW" to avoid package conflicts.
T_FN_ARROWReverts the change to how include/exclude patterns are processed for STDIN content; the change will return in 3.6.0.
Notes that the reverted STDIN include/exclude pattern change is not backwards compatible and will be re-introduced in 3.6.0.
All helper methods in the File class now throw RuntimeException instead of TokenizerException.
FileRuntimeExceptionTokenizerExceptionPSR12.Classes.ClassInstantiation changes its error code from MissingParenthesis to MissingParentheses.
PSR12.Classes.ClassInstantiationMissingParenthesisMissingParenthesesSquiz standard now forbids underscores for visibility of private member vars and methods, reversing the previous rule.
Changes the error message format for SpacingAfterOpen and SpacingBeforeClose from 3 pieces of data to 2.
SpacingAfterOpenSpacingBeforeCloseInclude patterns for sniffs now use OR logic instead of AND logic, so a file only needs to match at least one pattern.
Code that previously exited now throws
DeepExitException; catch it for the message and exit code.DeepExitException$e->getMessage()$e->getCode()Breaks backwards compatibility for all custom sniffs and custom reports in the 3.0 branch refactoring.
Refactors the code base and breaks backwards compatibility for all custom sniffs and custom reports.
Exit code 2 now indicates fixable errors were found; exit code 3 is used for general script execution errors.
PHPCBFRequires passing "-" on the command line for PHPCS to wait for STDIN.
-Makes sniff codes no longer optional; sniffs must specify an internal code for each error or warning.
The custom PHP_CodeSniffer test runner now requires a bootstrap file, affecting developers with custom standards using it.
Security7
Fixes a security issue where the Gitblame, Hgblame or Svnblame reports could execute attacker-controlled shell commands for files with shell metacharacters in their names.
GitblameHgblameSvnblameFullHighArbitrary shell execution
--filter=gitmodifiedHighFixes a security advisory where shell_exec() and exec() did not escape filenames and configuration settings, allowing arbitrary code execution.
shell_exec()exec()Notes that uses of shell_exec() and exec() were not escaping filenames and configuration settings in most cases.
shell_exec()exec()A properly crafted filename or configuration option would allow arbitrary code execution when using some features.
All users are encouraged to upgrade, especially those checking 3rd-party code, running PHPCS as a web service, or allowing user-defined tool paths.
If unable to upgrade while checking 3rd-party code, avoid the diff report, notify-send report, and the listed Debug and Syntax sniffs.
Generic.PHP.SyntaxGeneric.Debug.CSSLintGeneric.Debug.ClosureLinterGeneric.Debug.JSHintSquiz.Debug.JSLintSquiz.Debug.JavaScriptLintZend.Debug.CodeAnalyzerPlatform3
Adds runtime support for PHP 8.5 and fixes all known PHP 8.5 deprecation notices.
Adds runtime support for PHP 8.4 and fixes all known PHP 8.4 deprecation notices.
Raises the minimum PHP version from 5.1.2 to 5.4.0.
Deprecations to plan for
Deprecated36
Hard deprecates nearly everything previously soft deprecated, now showing deprecation notices.
Hard deprecates all sniffs which will be removed in 4.0.
Hard deprecates the deprecated Generator methods.
GeneratorHard deprecates the old array property setting format using comma separated strings.
Hard deprecates sniffs not implementing the PHP_CodeSniffer\Sniffs\Sniff interface.
PHP_CodeSniffer\Sniffs\SniffHard deprecates sniffs not following the naming conventions.
Hard deprecates standards called Internal.
Hard deprecates sniffs which don't listen for PHP, like JS/CSS specific sniffs.
Deprecates the Generic.Functions.CallTimePassByReference sniff, which will be removed in version 4.0.0.
Generic.Functions.CallTimePassByReferenceDeprecates support for sniffs not implementing the PHPCS Sniff interface, slated for removal in 4.0.
SniffDeprecates support for including sniffs that don't comply with PHPCS naming conventions by referencing the sniff file directly.
Deprecates support for external standards named "Internal".
Soft-deprecates several Generator print methods in favour of getFormatted equivalents.
PHP_CodeSniffer\Generators\Text::printTitle()PHP_CodeSniffer\Generators\Text::getFormattedTitle()PHP_CodeSniffer\Generators\Text::printTextBlock()PHP_CodeSniffer\Generators\Text::getFormattedTextBlock()PHP_CodeSniffer\Generators\Text::printCodeComparisonBlock()PHP_CodeSniffer\Generators\Text::getFormattedCodeComparisonBlock()PHP_CodeSniffer\Generators\Markdown::printHeader()PHP_CodeSniffer\Generators\Markdown::getFormattedHeader()Deprecates Markdown::printFooter() in favour of Markdown::getFormattedFooter().
PHP_CodeSniffer\Generators\Markdown::printFooter()PHP_CodeSniffer\Generators\Markdown::getFormattedFooter()Deprecates Markdown::printTextBlock() in favour of Markdown::getFormattedTextBlock().
PHP_CodeSniffer\Generators\Markdown::printTextBlock()PHP_CodeSniffer\Generators\Markdown::getFormattedTextBlock()Deprecates Markdown::printCodeComparisonBlock() in favour of Markdown::getFormattedCodeComparisonBlock().
PHP_CodeSniffer\Generators\Markdown::printCodeComparisonBlock()PHP_CodeSniffer\Generators\Markdown::getFormattedCodeComparisonBlock()Deprecates HTML::printHeader() in favour of HTML::getFormattedHeader().
PHP_CodeSniffer\Generators\HTML::printHeader()PHP_CodeSniffer\Generators\HTML::getFormattedHeader()Deprecates HTML::printToc() in favour of HTML::getFormattedToc().
PHP_CodeSniffer\Generators\HTML::printToc()PHP_CodeSniffer\Generators\HTML::getFormattedToc()Deprecates HTML::printFooter() in favour of HTML::getFormattedFooter().
PHP_CodeSniffer\Generators\HTML::printFooter()PHP_CodeSniffer\Generators\HTML::getFormattedFooter()Deprecates HTML::printTextBlock() in favour of HTML::getFormattedTextBlock().
PHP_CodeSniffer\Generators\HTML::printTextBlock()PHP_CodeSniffer\Generators\HTML::getFormattedTextBlock()Deprecates HTML::printCodeComparisonBlock() in favour of HTML::getFormattedCodeComparisonBlock().
PHP_CodeSniffer\Generators\HTML::printCodeComparisonBlock()PHP_CodeSniffer\Generators\HTML::getFormattedCodeComparisonBlock()Deprecates support for scanning JavaScript and CSS files, to be removed in version 4.0.0.
Deprecates all sniffs aimed only at JavaScript or CSS files, to be removed in version 4.0.0.
Deprecates the JavaScript and CSS Tokenizers and JS/CSS support in multi-file-type sniffs, to be removed in version 4.0.0.
Deprecates the abstract ExactMatch::getBlacklist() and ExactMatch::getWhitelist() methods, to be removed in 4.0.
PHP_CodeSniffer\Filters\ExactMatch::getBlacklist()PHP_CodeSniffer\Filters\ExactMatch::getWhitelist()Deprecates the MySource standard and all sniffs in it, to be removed in version 4.0.0.
MySourceDeprecates the Zend.Debug.CodeAnalyzer sniff, to be removed in version 4.0.0.
Zend.Debug.CodeAnalyzerExisting code using the old setSniffProperty() third parameter continues to work but throws a deprecation error.
Ruleset::setSniffProperty()The backwards compatibility layer for the setSniffProperty() third parameter will be removed in PHPCS 4.0.
Ruleset::setSniffProperty()Notes the namespaced name tokenizing revert will be removed in PHPCS 4.0 as the PHP 8.0 method is backported to pre 8.0.
Deprecates the Generic.Formatting.NoSpaceAfterCast sniff, to be removed in version 4.
Generic.Formatting.NoSpaceAfterCastGeneric.Formatting.SpaceAfterCastspacingDeprecates the Squiz.WhiteSpace.LanguageConstructSpacing sniff, moved to Generic.WhiteSpace.LanguageConstructSpacing and removed in version 4.
Squiz.WhiteSpace.LanguageConstructSpacingGeneric.WhiteSpace.LanguageConstructSpacingDeprecates the string syntax for setting array properties in rulesets in favor of element tags with key and value attributes, removed in version 4.
elementkeyvaluepropertyDeprecates the T_ARRAY_HINT token, removed in version 4; array type hints now use T_STRING.
T_ARRAY_HINTT_ARRAYT_STRINGDeprecates the T_RETURN_TYPE token, removed in version 4; use File::getMethodProperties() return_type index instead.
T_RETURN_TYPET_STRINGT_ARRAYFile::getMethodProperties()return_typenullable_return_typeDeprecates the @codingStandards comment syntax; it keeps working in all version 3 releases but will be removed in version 4.
@codingStandards