PHPCompatibility 9.0.0
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 aforeach()
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 thelist()
construct in aforeach()
statement. This was not supported prior to PHP 5.5. #657 - 🌟 New
PHPCompatibility.FunctionNameRestrictions.RemovedNamespacedAssert
sniff to detect declaring a function calledassert()
within a namespace. This has been deprecated as of PHP 7.3. #735. Partially fixes #718. - 🌟 New
PHPCompatibility.Lists.AssignmentOrder
sniff to detectlist()
constructs affected by the change in assignment order in PHP 7.0. #656 - 🌟 New
PHPCompatibility.Lists.NewKeyedList
sniff to detect usage of keys inlist()
, support for which was added in PHP 7.1. #655. Fixes #252. - 🌟 New
PHPCompatibility.Lists.NewListReferenceAssignment
sniff to detect reference assignments being used inlist()
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 thePHPCompatibility.LanguageConstructs.NewLanguageConstructs
sniff. - 🌟 New
PHPCompatibility.ParameterValues.ForbiddenGetClassNull
sniff to detectnull
being passed toget_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 thearray_reduce()
function, which was not supported before PHP 5.3. #666. Fixes #649 - 🌟 New
PHPCompatibility.ParameterValues.NewFopenModes
sniff to examine the$mode
parameter passed tofopen()
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 topack()
for formats not available in older PHP versions. #665 - 🌟 New
PHPCompatibility.ParameterValues.RemovedIconvEncoding
sniff to detect the PHP 5.6 deprecated encoding$type
s being passed toiconv_set_encoding()
. #660. Fixes #475. - 🌟 New
PHPCompatibility.ParameterValues.RemovedNonCryptoHashes
sniff to detect non-cryptographic hash algorithms being passed to varioushash_*()
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 thesetlocale()
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 newCompileError
andJsonException
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 thesapi_windows_*()
,hash_hkdf()
andpcntl_signal_get_handler()
functions as introduced in PHP 7.1. #728 - ⭐
PHPCompatibility.FunctionUse.RemovedFunctionParameters
sniff: recognize the deprecation of the$case_insensitive
parameter for thedefine()
function in PHP 7.3. #706 - ⭐
PHPCompatibility.FunctionUse.RemovedFunctions
sniff: recognize the PHP 7.3 deprecation of theimage2wbmp()
,fgetss()
andgzgetss()
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 forarray_push()
andarray_unshift()
becoming optional in PHP 7.3, as well as for the$mode
parameter for a range offtp_*()
functions becoming optional. #680 - ⭐
PHPCompatibility.IniDirectives.NewIniDirectives
sniff: recognize newsyslog
andsession
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()
andisVariable()
utility methods to thePHPCompatibility\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 newPHPCompatibility\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
ThePHPCompatibility.LanguageConstructs.NewLanguageConstructs
sniff now contains just the checks for the namespace separator and the ellipsis.
The newPHPCompatibility.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 thecomposer.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 thephp_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 forreturn
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. 👏