PHPCompatibility v9.0.0 Release Notes

Release Date: 2018-10-07 // over 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. New ConstantArraysUsingConst
    PHP.ConstantArraysUsingDefine InitialValue. New ConstantArraysUsingDefine
    PHP. Deprecated Functions FunctionUse. Removed Functions
    PHP. Deprecated IniDirectives IniDirectives. Removed IniDirectives
    PHP. Deprecated MagicAutoload FunctionNameRestrictions. Removed MagicAutoload
    PHP. Deprecated NewReference Syntax. Removed NewReference
    PHP. Deprecated PHP4StyleConstructors FunctionNameRestrictions. Removed PHP4StyleConstructors
    PHP. Deprecated TypeCasts TypeCasts. Removed TypeCasts
    PHP.DiscouragedSwitchContinue ControlStructures.DiscouragedSwitchContinue
    PHP.DynamicAccessToStatic Syntax. New DynamicAccessToStatic
    PHP.EmptyNonVariable LanguageConstructs. New EmptyNonVariable
    PHP.ForbiddenBreakContinueOutsideLoop ControlStructures.ForbiddenBreakContinueOutsideLoop
    PHP.ForbiddenBreakContinueVariableArguments ControlStructures.ForbiddenBreakContinueVariableArguments
    PHP.ForbiddenCallTimePassByReference Syntax.ForbiddenCallTimePassByReference
    PHP.Forbidden ClosureUseVariableNames FunctionDeclarations.Forbidden VariableNamesInClosureUse
    PHP.ForbiddenEmptyListAssignment Lists.ForbiddenEmptyListAssignment
    PHP.Forbidden Function ParametersWithSameName 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. New LateStaticBinding
    PHP. MbstringReplaceE Modifier ParameterValues. RemovedMbstring Modifier s
    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.NewHeredoc Initialize 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.New Scalar TypeDeclarations FunctionDeclarations.New Param TypeDeclarations
    PHP.NewTrailingComma Syntax.New FunctionCall TrailingComma
    PHP.NewTypeCasts TypeCasts.NewTypeCasts
    PHP.NewUseConstFunction UseDeclarations.NewUseConstFunction
    PHP.NonStaticMagicMethods FunctionDeclarations.NonStaticMagicMethods
    PHP.OptionalRequiredFunctionParameters FunctionUse.Optional To RequiredFunctionParameters
    PHP.ParameterShadowSuperGlobals FunctionDeclarations. Forbidden ParameterShadowSuperGlobals
    PHP. PCRENew Modifiers ParameterValues. NewPCRE Modifiers
    PHP. PregReplaceE Modifier ParameterValues. RemovedPCRE Modifier s
    PHP.RemovedAlternativePHPTags Miscellaneous.RemovedAlternativePHPTags
    PHP.RemovedConstants Constants.RemovedConstants
    PHP.RemovedExtensions Extensions.RemovedExtensions
    PHP.RemovedFunctionParameters FunctionUse.RemovedFunctionParameters
    PHP.RemovedGlobalVariables Variables.Removed Predefined GlobalVariables
    PHP.RemovedHashAlgorithms ParameterValues.RemovedHashAlgorithms
    PHP.ReservedFunctionNames FunctionNameRestrictions.ReservedFunctionNames
    PHP.RequiredOptionalFunctionParameters FunctionUse.Required To OptionalFunctionParameters
    PHP.ShortArray Syntax. New ShortArray
    PHP.Ternary Operators Operators. NewShort Ternary
    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.
      0๏ธโƒฃ 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. ๐Ÿ‘