github PHPCompatibility/PHPCompatibility 9.0.0
PHPCompatibility 9.0.0

latest releases: 9.3.5, 9.3.4, 9.3.3...
5 years ago

IMPORTANT: This release contains breaking changes. Please read the below information carefully before upgrading!

All sniffs have been placed in meaningful categories and a number of sniffs have been renamed to have more consistent, meaningful and future-proof names.

Both the PHPCompatibilityJoomla [GH | Packagist] as well as the PHPCompatibilityWP [GH | Packagist] rulesets have already been adjusted for this change and have released a new version which is compatible with this version of PHPCompatibility.

Aside from those CMS-based rulesets, this project now also offers a number of polyfill-library specific rulesets, such as PHPCompatibilityPasswordCompat [GH | Packagist] for @ircmaxell's password_compat libary, PHPCompatibilityParagonieRandomCompat and PHPCompatibilityParagonieSodiumCompat [GH | Packagist] for the Paragonie polyfills and a number of rulesets related to various polyfills offered by the Symfony project [GH | Packagist].

If your project uses one of these polyfills, please consider using these special polyfill rulesets to prevent false positives.

Also as of this version, Juliette Reinders Folmer is now officially a co-maintainer of this package.

Upgrade instructions

  • If you have <exclude name="..."/> directives in your own project's custom ruleset which relate to sniffs from the PHPCompatibility library, you will need to update your ruleset to use the new sniff names.
  • If you use the new PHPCS 3.2+ inline annotations, i.e. // phpcs:ignore Standard.Category.SniffName, in combination with PHPCompatibility sniff names, you will need to update these annotations.
  • If you use neither of the above, you should be fine and upgrading should be painless.

Overview of all the sniff renames:

Old Category.SniffName New Category.SniffName
PHP.ArgumentFunctionsUsage FunctionUse.ArgumentFunctionsUsage
PHP.CaseSensitiveKeywords Keywords.CaseSensitiveKeywords
PHP.ConstantArraysUsingConst InitialValue.NewConstantArraysUsingConst
PHP.ConstantArraysUsingDefine InitialValue.NewConstantArraysUsingDefine
PHP.DeprecatedFunctions FunctionUse.RemovedFunctions
PHP.DeprecatedIniDirectives IniDirectives.RemovedIniDirectives
PHP.DeprecatedMagicAutoload FunctionNameRestrictions.RemovedMagicAutoload
PHP.DeprecatedNewReference Syntax.RemovedNewReference
PHP.DeprecatedPHP4StyleConstructors FunctionNameRestrictions.RemovedPHP4StyleConstructors
PHP.DeprecatedTypeCasts TypeCasts.RemovedTypeCasts
PHP.DiscouragedSwitchContinue ControlStructures.DiscouragedSwitchContinue
PHP.DynamicAccessToStatic Syntax.NewDynamicAccessToStatic
PHP.EmptyNonVariable LanguageConstructs.NewEmptyNonVariable
PHP.ForbiddenBreakContinueOutsideLoop ControlStructures.ForbiddenBreakContinueOutsideLoop
PHP.ForbiddenBreakContinueVariableArguments ControlStructures.ForbiddenBreakContinueVariableArguments
PHP.ForbiddenCallTimePassByReference Syntax.ForbiddenCallTimePassByReference
PHP.ForbiddenClosureUseVariableNames FunctionDeclarations.ForbiddenVariableNamesInClosureUse
PHP.ForbiddenEmptyListAssignment Lists.ForbiddenEmptyListAssignment
PHP.ForbiddenFunctionParametersWithSameName FunctionDeclarations.ForbiddenParametersWithSameName
PHP.ForbiddenGlobalVariableVariable Variables.ForbiddenGlobalVariableVariable
PHP.ForbiddenNames Keywords.ForbiddenNames
PHP.ForbiddenNamesAsDeclared Keywords.ForbiddenNamesAsDeclared
PHP.ForbiddenNamesAsInvokedFunctions Keywords.ForbiddenNamesAsInvokedFunctions
PHP.ForbiddenNegativeBitshift Operators.ForbiddenNegativeBitshift
PHP.ForbiddenSwitchWithMultipleDefaultBlocks ControlStructures.ForbiddenSwitchWithMultipleDefaultBlocks
PHP.InternalInterfaces Interfaces.InternalInterfaces
PHP.LateStaticBinding Classes.NewLateStaticBinding
PHP.MbstringReplaceEModifier ParameterValues.RemovedMbstringModifiers
PHP.NewAnonymousClasses Classes.NewAnonymousClasses
PHP.NewArrayStringDereferencing Syntax.NewArrayStringDereferencing
PHP.NewClasses Classes.NewClasses
PHP.NewClassMemberAccess Syntax.NewClassMemberAccess
PHP.NewClosure FunctionDeclarations.NewClosure
PHP.NewConstants Constants.NewConstants
PHP.NewConstantScalarExpressions InitialValue.NewConstantScalarExpressions
PHP.NewConstVisibility Classes.NewConstVisibility
PHP.NewExecutionDirectives ControlStructures.NewExecutionDirectives
PHP.NewFunctionArrayDereferencing Syntax.NewFunctionArrayDereferencing
PHP.NewFunctionParameters FunctionUse.NewFunctionParameters
PHP.NewFunctions FunctionUse.NewFunctions
PHP.NewGeneratorReturn Generators.NewGeneratorReturn
PHP.NewGroupUseDeclarations UseDeclarations.NewGroupUseDeclarations
PHP.NewHashAlgorithms ParameterValues.NewHashAlgorithms
PHP.NewHeredocInitialize InitialValue.NewHeredoc
PHP.NewIniDirectives IniDirectives.NewIniDirectives
PHP.NewInterfaces Interfaces.NewInterfaces
PHP.NewKeywords Keywords.NewKeywords
PHP.NewLanguageConstructs LanguageConstructs.NewLanguageConstructs
PHP.NewMagicClassConstant Constants.NewMagicClassConstant
PHP.NewMagicMethods FunctionNameRestrictions.NewMagicMethods
PHP.NewMultiCatch ControlStructures.NewMultiCatch
PHP.NewNullableTypes FunctionDeclarations.NewNullableTypes
PHP.NewReturnTypeDeclarations FunctionDeclarations.NewReturnTypeDeclarations
PHP.NewScalarTypeDeclarations FunctionDeclarations.NewParamTypeDeclarations
PHP.NewTrailingComma Syntax.NewFunctionCallTrailingComma
PHP.NewTypeCasts TypeCasts.NewTypeCasts
PHP.NewUseConstFunction UseDeclarations.NewUseConstFunction
PHP.NonStaticMagicMethods FunctionDeclarations.NonStaticMagicMethods
PHP.OptionalRequiredFunctionParameters FunctionUse.OptionalToRequiredFunctionParameters
PHP.ParameterShadowSuperGlobals FunctionDeclarations.ForbiddenParameterShadowSuperGlobals
PHP.PCRENewModifiers ParameterValues.NewPCREModifiers
PHP.PregReplaceEModifier ParameterValues.RemovedPCREModifiers
PHP.RemovedAlternativePHPTags Miscellaneous.RemovedAlternativePHPTags
PHP.RemovedConstants Constants.RemovedConstants
PHP.RemovedExtensions Extensions.RemovedExtensions
PHP.RemovedFunctionParameters FunctionUse.RemovedFunctionParameters
PHP.RemovedGlobalVariables Variables.RemovedPredefinedGlobalVariables
PHP.RemovedHashAlgorithms ParameterValues.RemovedHashAlgorithms
PHP.ReservedFunctionNames FunctionNameRestrictions.ReservedFunctionNames
PHP.RequiredOptionalFunctionParameters FunctionUse.RequiredToOptionalFunctionParameters
PHP.ShortArray Syntax.NewShortArray
PHP.TernaryOperators Operators.NewShortTernary
PHP.ValidIntegers Miscellaneous.ValidIntegers
PHP.VariableVariables Variables.NewUniformVariableSyntax

Changelog for version 9.0.0

See all related issues and PRs in the 9.0.0 milestone.

Added

  • 🌟 New PHPCompatibility.ControlStructures.NewForeachExpressionReferencing sniff to detect referencing of $value within a foreach() when the iterated array is not a variable. This was not supported prior to PHP 5.5. #664
  • 🌟 New PHPCompatibility.ControlStructures.NewListInForeach sniff to detect unpacking nested arrays into separate variables via the list() construct in a foreach() statement. This was not supported prior to PHP 5.5. #657
  • 🌟 New PHPCompatibility.FunctionNameRestrictions.RemovedNamespacedAssert sniff to detect declaring a function called assert() within a namespace. This has been deprecated as of PHP 7.3. #735. Partially fixes #718.
  • 🌟 New PHPCompatibility.Lists.AssignmentOrder sniff to detect list() constructs affected by the change in assignment order in PHP 7.0. #656
  • 🌟 New PHPCompatibility.Lists.NewKeyedList sniff to detect usage of keys in list(), support for which was added in PHP 7.1. #655. Fixes #252.
  • 🌟 New PHPCompatibility.Lists.NewListReferenceAssignment sniff to detect reference assignments being used in list() constructs, support for which has been added in PHP 7.3. #731
  • 🌟 New PHPCompatibility.Lists.NewShortList sniff to detect the shorthand array syntax [] being used for symmetric array destructuring as introduced in PHP 7.1. #654. Fixes #248.
  • 🌟 New PHPCompatibility.Operators.NewOperators sniff which checks for usage of the pow, pow equals, spaceship and coalesce (equals) operators. #738
    These checks were previously contained within the PHPCompatibility.LanguageConstructs.NewLanguageConstructs sniff.
  • 🌟 New PHPCompatibility.ParameterValues.ForbiddenGetClassNull sniff to detect null being passed to get_class(), support for which has been removed in PHP 7.2 #659. Fixes #557.
  • 🌟 New PHPCompatibility.ParameterValues.NewArrayReduceInitialType sniff to detect non-integers being passed as the $initial parameter to the array_reduce() function, which was not supported before PHP 5.3. #666. Fixes #649
  • 🌟 New PHPCompatibility.ParameterValues.NewFopenModes sniff to examine the $mode parameter passed to fopen() for modes not available in older PHP versions. #658
  • 🌟 New PHPCompatibility.ParameterValues.NewNegativeStringOffset sniff to detect negative string offsets being passed to string manipulation functions which was not supported before PHP 7.1. #662. Partially fixes #253.
  • 🌟 New PHPCompatibility.ParameterValues.NewPackFormats sniff to examine the $format parameter passed to pack() for formats not available in older PHP versions. #665
  • 🌟 New PHPCompatibility.ParameterValues.RemovedIconvEncoding sniff to detect the PHP 5.6 deprecated encoding $types being passed to iconv_set_encoding(). #660. Fixes #475.
  • 🌟 New PHPCompatibility.ParameterValues.RemovedNonCryptoHashes sniff to detect non-cryptographic hash algorithms being passed to various hash_*() functions. This is no longer accepted as of PHP 7.2. #663. Fixes #559
  • 🌟 New PHPCompatibility.ParameterValues.RemovedSetlocaleString sniff to detect string literals being passed to the $category parameter of the setlocale() function. This behaviour was deprecated in PHP 4.2 and support has been removed in PHP 7.0. #661
  • 🌟 New PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc sniff to detect the new heredoc/nowdoc format as allowed as of PHP 7.3. #736. Fixes #705.
    Note: This sniff is only supported in combination with PHP_CodeSniffer 2.6.0 and higher.
  • PHPCompatibility.Classes.NewClasses sniff: recognize the new CompileError and JsonException classes as introduced in PHP 7.3. #676
  • PHPCompatibility.Constants.NewConstants sniff: recognize new constants which are being introduced in PHP 7.3. #678
  • PHPCompatibility.Constants.RemovedConstants sniff: recognize constants which have been deprecated or removed in PHP 7.3. #710. Partially fixes #718.
  • PHPCompatibility.FunctionUse.NewFunctions sniff: recognize various new functions being introduced in PHP 7.3. #679
  • PHPCompatibility.FunctionUse.NewFunctions sniff: recognize the sapi_windows_*(), hash_hkdf() and pcntl_signal_get_handler() functions as introduced in PHP 7.1. #728
  • PHPCompatibility.FunctionUse.RemovedFunctionParameters sniff: recognize the deprecation of the $case_insensitive parameter for the define() function in PHP 7.3. #706
  • PHPCompatibility.FunctionUse.RemovedFunctions sniff: recognize the PHP 7.3 deprecation of the image2wbmp(), fgetss() and gzgetss() functions, as well as the deprecation of undocumented Mbstring function aliases. #681, #714, #720. Partially fixes #718.
  • PHPCompatibility.FunctionUse.RequiredToOptionalFunctionParameters sniff: account for the second parameter for array_push() and array_unshift() becoming optional in PHP 7.3, as well as for the $mode parameter for a range of ftp_*() functions becoming optional. #680
  • PHPCompatibility.IniDirectives.NewIniDirectives sniff: recognize new syslog and session ini directives as introduced in PHP 7.3. #702, #719, #730
  • PHPCompatibility.IniDirectives.NewIniDirectives sniff: recognize some more ini directives which were introduced in PHP 7.1. #727
  • PHPCompatibility.IniDirectives.RemovedIniDirectived sniff: recognize ini directives removed in PHP 7.3. #677, #717. Partially fixes #718.
  • ⭐ New isNumericCalculation() and isVariable() utility methods to the PHPCompatibility\Sniff class. #664, #666
  • 📚 A section about the new sniff naming conventions to the Contributing file. #738

Changed

  • 🔥 All sniffs have been placed in meaningful categories and a number of sniffs have been renamed to have more consistent, meaningful and future-proof names. #738. Fixes #601, #692
    See the table at the top of this changelog for details of all the file renames.
  • ☔ The unit test files have been moved about as well. #738
    • The directory structure for these now mirrors the default directory structure used by PHPCS itself.
    • The file names of the unit test files have been adjusted for the changes made in the sniffs.
    • The unit test case files have been renamed and moved to the same directory as the actual test file they apply to.
    • The BaseSniffTest::sniffFile() method has been adjusted to match. The signature of this method has changed. Where it previously expected a relative path to the unit test case file, it now expects an absolute path.
    • The unit tests for the utility methods in the PHPCompatibility\Sniff class have been moved to a new PHPCompatibility\Util\Tests\Core subdirectory.
    • The bootstrap file used for PHPUnit has been moved to the project root directory and renamed phpunit-bootstrap.php.
  • 🔀 The PHPCompatibility.LanguageConstructs.NewLanguageConstructs sniff has been split into two sniffs. #738
    The PHPCompatibility.LanguageConstructs.NewLanguageConstructs sniff now contains just the checks for the namespace separator and the ellipsis.
    The new PHPCompatibility.Operators.NewOperators sniff now contains the checks regarding the pow, pow equals, spaceship and coalesce (equals) operators.
  • 📌 The PHPCompatibility.ParameterValues.RemovedMbstringModifiers sniff will now also recognize removed regex modifiers when used within a function call to one of the undocumented Mbstring function aliases for the Mbstring regex functions. #715
  • 📌 The PHPCompatibility\Sniff::getFunctionCallParameter() utility method now allows for closures called via a variable. #723
  • ✏️ PHPCompatibility.Upgrade.LowPHPCS: the minimum supported PHPCS version is now 2.3.0. #699
  • ✏️ Minor inline documentation improvements. #738
  • ☔ Minor improvements to the unit tests for the PHPCompatibility.FunctionNameRestrctions.RemovedMagicAutoload sniff. #716
  • ♻️ Minor other optimizations. #698, #697
  • 🔧 Minor improvements to the build tools. #701
  • 🔧 Removed some unnecessary inline annotations. #700
  • 📚 Replaced some of the badges in the Readme file. #721, #722
  • 📚 Composer: updated the list of package authors. #739

Removed

  • 🚫 Support for PHP_CodeSniffer 1.x and low 2.x versions. The new minimum version of PHP_CodeSniffer to be able to use this library is 2.3.0. #699. Fixes #691.
    The minimum recommended version of PHP_CodeSniffer remains the same, i.e. 2.6.0.
  • 🚫 The \PHPCompatibility\Sniff::inUseScope() method has been removed as it is no longer needed now support for PHPCS 1.x has been dropped. #699
  • 🚫 Composer: The autoload section has been removed from the composer.json file. #738. Fixes #568.
    Autoloading for this library is done via the PHP_CodeSniffer default mechanism, enhanced with our own autoloader, so the Composer autoloader shouldn't be needed and was causing issues in a particular use-case.

Fixed

  • 🐛 PHPCompatibility.FunctionUse.NewFunctionParameters sniff: The new $mode parameter of the php_uname() function was added in PHP 4.3, not in PHP 7.0 as was previously being reported.
    The previous implementation of this check was based on an error in the PHP documentation. The error in the PHP documentation has been rectified and the sniff has followed suit. #711
  • 🐛 PHPCompatibility.Generators.NewGeneratorReturn sniff: The sniff would throw false positives for return statements in nested constructs and did not correctly detect the scope which should be examined. #725. Fixes #724.
  • 🐛 PHPCompatibility.Keywords.NewKeywords sniff: PHP magic constants are case _in_sensitive. This sniff now accounts for this. #707
  • 🐛 Various bugs in the PHPCompatibility.Syntax.ForbiddenCallTimePassByReference sniff #723:
    • Closures called via a variable will now also be examined. (false negative)
    • References within arrays/closures passed as function call parameters would incorrectly trigger an error. (false positive)
  • 💚 Compatibility with PHPUnit 7.2. #712

Credits

Thanks go out to Jonathan Champ for his contribution to this version. 👏

Don't miss a new PHPCompatibility release

NewReleases is sending notifications on new releases.