PHP Compatibility check for PHP_CodeSniffer
LGPL-3.0 License
Bot releases are hidden (Show)
See all related issues and PRs in the 9.3.5 milestone.
PHPCompatibility.Classes.NewClasses
sniff: recognize the new FFI
extension related classes as introduced in PHP 7.4. #949
PHPCompatibility.IniDirectives.NewIniDirectives
sniff: detect use of the new FFI
extension related ini directives as introduced in PHP 7.4. #949
PHPCompatibility.Syntax.NewShortArray
: improved clarity of the error message and made it consistent with other error messages in this standard. #934
PHPCompatibility.Interfaces.NewInterfaces
: updated the URL which is mentioned in select error messages. #942
PHPCompatibility.Classes.NewClasses
: two new PHP 7.4 classes were being checked as if they were Exceptions. #945
Thanks go out to William Entriken for their contribution to this version. 👏
Published by jrfnl almost 5 years ago
See all related issues and PRs in the 9.3.4 milestone.
PHPCompatibility.Keywords.ForbiddenNames
: false positive for list
when used in a foreach()
condition. #930. Fixes #928, #929
Thanks go out to Sergii Bondarenko for their contribution to this version. 👏
Published by jrfnl almost 5 years ago
See all related issues and PRs in the 9.3.3 milestone.
PHPCompatibility.Constants.NewConstants
sniff: detection of yet more (undocumented) PHP 7.2 Sodium constants. #924
PHPCompatibility.Keywords.ForbiddenNames
sniff: detect the use of more reserved keywords which are not allowed to be used to name certain constructs. #923. Fixes #922
PHPCompatibility.FunctionNameRestrictions.RemovedPHP4StyleConstructors
: false positive detecting PHP4-style constructors when declared in interfaces. The class implementing the interface will not have the same name as the interface, so the actual method would not be regarded as a PHP4 style constructor. #921
Thanks go out to Nikhil for their contribution to this version. 👏
Published by jrfnl about 5 years ago
See all related issues and PRs in the 9.3.2 milestone.
PHPCompatibility.Constants.NewConstants
sniff: detection of the PHP 7.2 SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13
constant. #915
PHPCompatibility.FunctionNameRestrictions.RemovedPHP4StyleConstructors
: minor efficiency fix to make the sniff faster. #912
PHPCompatibility.FunctionNameRestrictions.ReservedFunctionNames
: functions marked as @deprecated
in the function docblock will now be ignored by this sniff. #917. Fixes #911
PHPCompatibility.FunctionDeclarations.ForbiddenToStringParameters
: the $ooScopeTokens
property is now protected
, it should never have been public
in the first place. #907
PHPCompatibility.FunctionUse.OptionalToRequiredFunctionParameters
: false positive when a class is instantiated which has the same name as one of the affected functions. #914. Fixes #913
PHPCompatibility.FunctionUse.RequiredToOptionalFunctionParameters
: false positive when a class is instantiated which has the same name as one of the affected functions. #914
PHPCompatibility.MethodUse.NewDirectCallsToClone
: false positive on calling __clone()
from within the class being cloned #910. Fixes #629 (comment)
PHPCompatibility.Miscellaneous.ValidIntegers
: binary numbers using an uppercase B
were not always recognized correctly. #909
Published by jrfnl about 5 years ago
See all related issues and PRs in the 9.3.1 milestone.
PHPCompatibility.ParameterValues.RemovedImplodeFlexibleParamOrder
: false positive when an array item in the second parameter contained a ternary. #891. Fixes #890
PHPCompatibility.ParameterValues.RemovedImplodeFlexibleParamOrder
: will now take array casts into account when determining which parameter is $pieces
. #891.PHPCompatibility.ParameterValues.RemovedImplodeFlexibleParamOrder
: hardening of the logic to not examine the second parameter when the first is just and only a text string ($glue
). #891.Published by jrfnl about 5 years ago
See all related issues and PRs in the 9.3.0 milestone.
To keep informed of the progress of covering "everything PHP 7.4" in PHPCompatibility, please subscribe to issue #808.
The next version of PHPCompatibility is expected to include a new external dependency.
In this same release, support for PHP < 5.4 and PHP_CodeSniffer < 2.6.0 will be dropped.
The 10.0.0
release is expected around the same time as the release of PHP 7.4 - end of November/beginning of December 2019.
PHPCompatibility.Miscellaneous.NewPHPOpenTagEOF
sniff to detect a stand-alone PHP open tag at the end of a file, without trailing newline, as will be supported as of PHP 7.4. #843
PHPCompatibility.ParameterValues.ForbiddenStripTagsSelfClosingXHTML
sniff to detect calls to strip_tags()
passing self-closing XHTML tags in the $allowable_tags
parameter. This has not been supported since PHP 5.3.4. #866
PHPCompatibility.ParameterValues.NewHTMLEntitiesEncodingDefault
sniff to detect calls to html_entity_decode()
, htmlentities()
and htmlspecialchars()
which are impacted by the change to the default value of the $encoding
parameter in PHP 5.4. #862
PHPCompatibility.ParameterValues.NewIconvMbstringCharsetDefault
sniff to detect code impacted by the change in the default_charset
value in PHP 5.6. #864 Fixes #839
PHPCompatibility.ParameterValues.NewIDNVariantDefault
sniff to detect calls to idn_to_ascii()
and idn_to_utf8()
impacted by the PHP 7.4 change in the default value for the $variant
parameter. #861
PHPCompatibility.ParameterValues.NewPasswordAlgoConstantValues
sniff to detect calls to password_hash()
and password_needs_rehash()
impacted by the changed value of the PASSWORD_DEFAULT
, PASSWORD_BCRYPT
, PASSWORD_ARGON2I
and PASSWORD_ARGON2ID
constants in PHP 7.4. #865
PHPCompatibility.ParameterValues.NewProcOpenCmdArray
sniff to detect calls to proc_open()
passing an array for the $cmd
parameter as supported as of PHP 7.4. #869
PHPCompatibility.ParameterValues.NewStripTagsAllowableTagsArray
sniff to detect calls to strip_tags()
passing an array for the $allowable_tags
parameter as will be supported as of PHP 7.4. #867
PHPCompatibility.ParameterValues.RemovedImplodeFlexibleParamOrder
sniff to detect implode()
being called with $glue
and $pieces
in reverse order from the documented argument order. This was previously allowed for historical reasons, but will be deprecated in PHP 7.4. #846
PHPCompatibility.ParameterValues.RemovedMbStrrposEncodingThirdParam
sniff to detect the $encoding
being passed as the third, instead of the fourth parameter, to mb_strrpos()
as has been soft deprecated since PHP 5.2 and will be hard deprecated as of PHP 7.4. #860
PHPCompatibility.Syntax.RemovedCurlyBraceArrayAccess
sniff to detect array and string offset access using curly braces as will be deprecated as of PHP 7.4. #855
PHPCompatibility.TextStrings.NewUnicodeEscapeSequence
sniff to detect use of the PHP 7.0+ unicode codepoint escape sequences and issues with invalid sequences. #856
PHPCompatibility.Upgrade.LowPHP
sniff to give users of old PHP versions advance warning when support will be dropped in the near future. #838PHPCompatibility.Classes.NewClasses
sniff: recognize the new WeakReference
class as introduced in PHP 7.4. #857
PHPCompatibility.Constants.NewConstants
sniff: detection of new Curl constants as introduced in PHP 7.3.5. #878
PHPCompatibility.Constants.NewConstants
sniff: detection of the revived T_BAD_CHARACTER
constant as re-introduced in PHP 7.4. #882
PHPCompatibility.Constants.NewConstants
sniff: detection of the new IMG_FILTER_SCATTER
and PASSWORD_ARGON2_PROVIDER
constants as introduced in PHP 7.4. #887
PHPCompatibility.Constants.RemovedConstants
sniff: detection of use of the CURLPIPE_HTTP1
constant which will be deprecated in PHP 7.4. #879
PHPCompatibility.Constants.RemovedConstants
sniff: detection of use of the FILTER_SANITIZE_MAGIC_QUOTES
constant which will be deprecated in PHP 7.4. #845
PHPCompatibility.Constants.RemovedConstants
sniff: detection of use of the T_CHARACTER
and T_BAD_CHARACTER
constants which were removed in PHP 7.0. #882
PHPCompatibility.FunctionDeclarations.NewMagicMethods
sniff: recognize the new __serialize()
and __unserialize()
magic methods as introduced in PHP 7.4. #868
PHPCompatibility.FunctionDeclarations.NewMagicMethods
sniff: recognize the PHP 5.0 __construct()
and __destruct()
magic methods. #884
PHPCompatibility.FunctionDeclarations.NonStaticMagicMethods
sniff: recognize the new __serialize()
and __unserialize()
magic methods as introduced in PHP 7.4. #868
PHPCompatibility.FunctionUse.NewFunctions
sniff: recognize the new PHP 7.4 function imagecreatefromtga()
. #873
PHPCompatibility.FunctionUse.RemovedFunctionParameters
sniff: recognize the deprecation of the $age
parameter of the curl_version()
function. #874
PHPCompatibility.FunctionUse.RemovedFunctions
sniff: recognize the PHP 7.4 deprecated convert_cyr_string()()
, ezmlm_hash()
, get_magic_quotes_gpc()
, get_magic_quotes_runtime()
, hebrevc()
, is_real()
, money_format()
and restore_include_path()
functions. #847
PHPCompatibility.IniDirectives.NewIniDirectives
sniff: detect use of the new PHP 7.4 zend.exception_ignore_args
ini directive. #871
PHPCompatibility.IniDirectives.RemovedIniDirectives
sniff: detect use of the allow_url_include
ini directive which is deprecated as of PHP 7.4. #870
PHPCompatibility.IniDirectives.RemovedIniDirectives
sniff: detection of use of the opcache.load_comments
directive which was removed in PHP 7.0. #883
PHPCompatibility.ParameterValues.NewHashAlgorithms
: recognize use of the new PHP 7.4 crc32c
hash algorithm. #872
PHPCompatibility.TypeCasts.RemovedTypeCasts
sniff: detect usage of the (real)
type cast which will be deprecated in PHP 7.4. #844
recode
extension functionality which will be removed in PHP 7.4 (moved to PECL) in the RemovedExtensions
and RemovedFunctions
sniffs. #841
OPcache
extension functionality which was be introduced in PHP 5.5, but not yet fully accounted for in the NewFunctions
and NewIniDirectives
sniffs. #883
getCompleteTextString()
utility method to the PHPCompatibility\Sniff
class. #856
PHPCompatibility.Upgrade.LowPHPCS
sniff.PHPCompatibility.ParameterValues.NewNegativeStringOffset
, PHPCompatibility.ParameterValues.RemovedMbStringModifiers
and sniffs. #876, #877
CONTRIBUTING.md
: Added a list of typical sources for information about changes to PHP. #875
PHPCompatibility.FunctionDeclarations.NewExceptionsFromToString
sniff: the sniff will now also examine the function docblock, if available, and will throw an error when a @throws
tag is found in the docblock. #880. Fixes #863
PHPCompatibility.FunctionDeclarations.NonStaticMagicMethods
sniff: will now also check the visibility and static
(or not) requirements of the magic __construct()
, __destruct()
, __clone()
, __debugInfo()
, __invoke()
and __set_state()
methods. #885
PHPCompatibility.Syntax.NewArrayStringDereferencing
sniff: the sniff will now also recognize array string dereferencing using curly braces as was (silently) supported since PHP 7.0. #851
PHPCompatibility.Syntax.NewClassMemberAccess
sniff: the sniff will now also recognize class member access on instantiation and cloning using curly braces as was (silently) supported since PHP 7.0. #852
PHPCompatibility.Syntax.NewFunctionArrayDereferencing
sniff: the sniff will now also recognize function array dereferencing using curly braces as was (silently) supported since PHP 7.0. #853
PHPCompatibility.FunctionDeclarations.ForbiddenParametersWithSameName
sniff: variable names are case-sensitive, so recognition of same named parameters should be done in a case-sensitive manner. #848
PHPCompatibility.FunctionDeclarations.NewExceptionsFromToString
sniff: Exceptions thrown within a try
should not trigger the sniff. #880. Fixes #863
PHPCompatibility.FunctionDeclarations.NewExceptionsFromToString
sniff: the $ooScopeTokens
property should never have been a public property. #880.PHPCompatibility.Operators.RemovedTernaryAssociativity
sniff were not being run. #836
Published by jrfnl over 5 years ago
See all related issues and PRs in the 9.2.0 milestone.
To keep informed of the progress of covering "everything PHP 7.4" in PHPCompatibility, please subscribe to issue #808.
PHPCompatibility.Classes.ForbiddenAbstractPrivateMethods
sniff to detect methods declared as both private
as well as abstract
. This was allowed between PHP 5.0.0 and 5.0.4, but disallowed in PHP 5.1 as the behaviour of private
and abstract
are mutually exclusive. #822
PHPCompatibility.Classes.NewTypedProperties
sniff to detect PHP 7.4 typed property declarations. #801, #829
PHPCompatibility.Classes.RemovedOrphanedParent
sniff to detect the use of the parent
keyword in classes without a parent (non-extended classes). This code pattern is deprecated in PHP 7.4 and will become a compile-error in PHP 8.0. #818
PHPCompatibility.FunctionDeclarations.NewExceptionsFromToString
sniff to detect throwing exceptions from __toString()
methods. This would previously result in a fatal error, but will be allowed as of PHP 7.4. #814
PHPCompatibility.FunctionDeclarations.ForbiddenToStringParameters
sniff to detect __toString()
function declarations expecting parameters. This was disallowed in PHP 5.3. #815
PHPCompatibility.MethodUse.ForbiddenToStringParameters
sniff to detect direct calls to __toString()
magic methods passing parameters. This was disallowed in PHP 5.3. #830
PHPCompatibility.Operators.ChangedConcatOperatorPrecedence
sniff to detect code affected by the upcoming change in operator precedence for the concatenation operator. The concatenation operator precedence will be lowered in PHP 8.0, with deprecation notices for code affected being thrown in PHP 7.4. #805
PHPCompatibility.Operators.RemovedTernaryAssociativity
sniff to detect code relying on left-associativity of the ternary operator. This behaviour will be deprecated in PHP 7.4 and removed in PHP 8.0. #810
PHPCompatibility.Syntax.NewArrayUnpacking
sniff to detect the use of the spread operator to unpack arrays when declaring a new array, as introduced in PHP 7.4. #804
PHPCompatibility.Classes.NewClasses
sniff: recognize the new ReflectionReference
class as introduced in PHP 7.4. #820
PHPCompatibility.Constants.NewConstants
sniff: detection of the new PHP 7.4 Core (Standard), MBString, Socket and Tidy constants. #821
PHPCompatibility.FunctionUse.NewFunctions
sniff: detect usage of the new PHP 7.4 get_mangled_object_vars()
, mb_str_split()
, openssl_x509_verify()
, password_algos()
, pcntl_unshare()
, sapi_windows_set_ctrl_handler()
and sapi_windows_generate_ctrl_event()
functions. #811, #819, #827
PHPCompatibility.FunctionUse.NewFunctions
sniff: recognize the new OCI functions as introduced in PHP 7.2.14 and PHP 7.3.1. #786
PHPCompatibility.FunctionUse.RemovedFunctions
sniff: recognize the PHP 7.4 deprecated ldap_control_paged_result_response()
and ldap_control_paged_result()
functions. #831
PHPCompatibility.FunctionUse.RemovedFunctions
sniff: recognize the Payflow Pro/pfpro
functions as removed in PHP 5.1. #823
PHPCompatibility.FunctionUse.RequiredToOptionalFunctionParameters
sniff: account for the parameters for array_merge()
and array_merge_recursive()
becoming optional in PHP 7.4. #817
PHPCompatibility.IniDirectives.RemovedIniDirectives
sniff: recognize the Payflow Pro/pfpro
ini directives as removed in PHP 5.1. #823
interbase/Firebird
extension functionality which will be removed in PHP 7.4 (moved to PECL) in the RemovedConstants
, RemovedExtensions
, RemovedFunctions
and RemovedIniDirectives
sniffs. #807
wddx
extension functionality which will be removed in PHP 7.4 (moved to PECL) in the RemovedExtensions
and RemovedFunctions
sniffs. #826
isShortTernary()
and isUnaryPlusMinus()
utility methods to the PHPCompatibility\Sniff
class. #810, #805
PHPCompatibility.Extensions.RemovedExtensions
sniff will now only report on the removed Payflow Pro
extension when a function uses pfpro_
as a prefix. Previously, it used the pfpro
prefix (without underscore) for detection. #812
T_ELLIPSIS
token, i.e. the spread operator, is detected. #803PHPCompatibility.FunctionDeclarations.NewParamTypeDeclarations
is now also tested with parameters using the splat operator. #802
PHP_CodeSniffer
as the canonical entry point for PHP_CodeSniffer
. Previously, it would point to the PEAR package. #788
PHPCompatibility/PHPCompatibility
repo and no longer to the (deprecated) wimg/PHPCompatibility
repo. #828
DealerDirect/phpcodesniffer-composer-installer
Composer plugin has been upped to 0.5.0
. #791
PHPCompatibility.Extensions.RemovedExtensions
sniff contained a typo in the alternative recommended for the removed mcve
extension. #806
PHPCompatibility.Extensions.RemovedExtensions
sniff listed the wrong removal version number for the Payflow Pro/pfpro
extension (PHP 5.3 instead of the correct 5.1). #823
Thanks go out to Yılmaz and Tim Millwood for their contribution to this version. 👏
Published by jrfnl almost 6 years ago
See all related issues and PRs in the 9.1.1 milestone.
Published by jrfnl almost 6 years ago
See all related issues and PRs in the 9.1.0 milestone.
PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue
sniff to detect code which could be affected by the PHP 7.0 change in the values reported by func_get_arg()
, func_get_args()
, debug_backtrace()
and exception backtraces. #750. Fixes #585.PHPCompatibility.MethodUse.NewDirectCallsToClone
sniff to detect direct call to a __clone()
magic method which wasn't allowed prior to PHP 7.0. #743. Fixes #629.PHPCompatibility.Variables.ForbiddenThisUseContext
sniff to detect most of the inconsistencies surrounding the use of the $this
variable, which were removed in PHP 7.1. #762, #771. Fixes #262 and #740.NewClasses
: detection of more native PHP Exceptions. #743, #753
NewConstants
: detection of the new PHP 7.3 Curl, Stream Crypto and LDAP constants and some more PHP 7.0 Tokenizer constants. #752, #767, #778
NewFunctions
sniff: recognize (more) new LDAP functions as introduced in PHP 7.3. #768
NewFunctionParameters
sniff: recognize the new $serverctrls
parameter which was added to a number of LDAP functions in PHP 7.3. #769
NewIniDirectives
sniff: recognize the new imap.enable_insecure_rsh
ini directive as introduced in PHP 7.1.25, 7.2.13 and 7.3.0. #770
NewInterfaces
sniff: recognize two more Session related interfaces which were introduced in PHP 5.5.1 and 7.0 respectively. #748
findStartOfStatement()
method to the PHPCompatibility\PHPCSHelper
class to allow for PHPCS cross-version usage of that method. #750
RemovedPHP4StyleConstructors
: will now also detect PHP4-style constructors when declared in interfaces. #751
Sniff::validDirectScope()
: the return value of this method has changed. Previously it would always be a boolean. It will stil return false
when no valid direct scope has been found, but it will now return the stackPtr
to the scope token if a valid direct scope was encountered. #758
NewOperators
: updated the version number for T_COALESCE_EQUAL
. #746
Tokenizer
regarding binary type casts. #760
InternalInterfaces
: false negative for implemented/extended interfaces prefixed with a namespace separator. #775
NewClasses
: the introduction version of various native PHP Exceptions has been corrected. #743, #753
NewInterfaces
: false negative for implemented/extended interfaces prefixed with a namespace separator. #775
RemovedPHP4StyleConstructors
: the sniff would examine methods in nested anonymous classes as if they were methods of the higher level class. #751
RemovedPHP4StyleConstructors
: the sniff will no longer throw false positives for the first method in an anonymous class when used in combination with PHPCS 2.3.x. #751
ReservedFunctionNames
: fixed incorrect error message text for methods in anonymous classes when used in combination with PHPCS 2.3.x. #755
ReservedFunctionNames
: prevent duplicate errors being thrown for methods in nested anonymous classes. #755
PHPCSHelper::findEndOfStatement()
: minor bug fix. #749
Sniff::isClassProperty()
: class properties for classes nested in conditions or function calls were not always recognized as class properties. #758
Thanks go out to Jonathan Champ for his contribution to this version. 👏
Published by jrfnl about 6 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.
<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.// phpcs:ignore Standard.Category.SniffName
, in combination with PHPCompatibility sniff names, you will need to update these annotations.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 |
See all related issues and PRs in the 9.0.0 milestone.
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
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
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.PHPCompatibility.Lists.AssignmentOrder
sniff to detect list()
constructs affected by the change in assignment order in PHP 7.0. #656
PHPCompatibility.Lists.NewKeyedList
sniff to detect usage of keys in list()
, support for which was added in PHP 7.1. #655. Fixes #252.PHPCompatibility.Lists.NewListReferenceAssignment
sniff to detect reference assignments being used in list()
constructs, support for which has been added in PHP 7.3. #731
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.PHPCompatibility.Operators.NewOperators
sniff which checks for usage of the pow, pow equals, spaceship and coalesce (equals) operators. #738PHPCompatibility.LanguageConstructs.NewLanguageConstructs
sniff.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.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
PHPCompatibility.ParameterValues.NewFopenModes
sniff to examine the $mode
parameter passed to fopen()
for modes not available in older PHP versions. #658
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.PHPCompatibility.ParameterValues.NewPackFormats
sniff to examine the $format
parameter passed to pack()
for formats not available in older PHP versions. #665
PHPCompatibility.ParameterValues.RemovedIconvEncoding
sniff to detect the PHP 5.6 deprecated encoding $type
s being passed to iconv_set_encoding()
. #660. Fixes #475.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
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
PHPCompatibility.Syntax.NewFlexibleHeredocNowdoc
sniff to detect the new heredoc/nowdoc format as allowed as of PHP 7.3. #736. Fixes #705.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.isNumericCalculation()
and isVariable()
utility methods to the PHPCompatibility\Sniff
class. #664, #666
Contributing
file. #738
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.PHPCompatibility\Sniff
class have been moved to a new PHPCompatibility\Util\Tests\Core
subdirectory.phpunit-bootstrap.php
.PHPCompatibility.LanguageConstructs.NewLanguageConstructs
sniff has been split into two sniffs. #738PHPCompatibility.LanguageConstructs.NewLanguageConstructs
sniff now contains just the checks for the namespace separator and the ellipsis.PHPCompatibility.Operators.NewOperators
sniff now contains the checks regarding the pow, pow equals, spaceship and coalesce (equals) operators.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
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
PHPCompatibility.FunctionNameRestrctions.RemovedMagicAutoload
sniff. #716
\PHPCompatibility\Sniff::inUseScope()
method has been removed as it is no longer needed now support for PHPCS 1.x has been dropped. #699
autoload
section has been removed from the composer.json
file. #738. Fixes #568.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.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
PHPCompatibility.Syntax.ForbiddenCallTimePassByReference
sniff #723:
Thanks go out to Jonathan Champ for his contribution to this version. 👏
Published by jrfnl over 6 years ago
As of July 13 2018, the PHPCompatibility repository has moved from the personal account of Wim Godden wimg
to its own organization PHPCompatibility
.
Composer users are advised to update their composer.json
. The dependency is now called phpcompatibility/php-compatibility
.
Within this new organization, hosting will be offered for framework/CMS specific PHPCompatibility rulesets.
The first two such repositories have been created and are now available for use:
If you want to make sure you have all PHPCompatibility rulesets available at any time, you can use the PHPCompatibilityAll package GitHub | Packagist.
For more information, see the Readme and Contributing guidelines.
The next version of PHPCompatibility will include a major directory layout restructuring which means that the sniff codes of all sniffs will change.
In this same release, support for PHP_CodeSniffer 1.5.x will be dropped. The new minimum supported PHPCS version will be 2.3.0.
For more information about these upcoming changes, please read the announcement.
The 9.0.0
release is expected to be ready later this summer.
See all related issues and PRs in the 8.2.0 milestone.
ArgumentFunctionsUsage
sniff to detect usage of the func_get_args()
, func_get_arg()
and func_num_args()
functions and the changes regarding these functions introduced in PHP 5.3. #596. Fixes #372.DiscouragedSwitchContinue
sniff to detect continue
targetting a switch
control structure for which E_WARNINGS
will be thrown as of PHP 7.3. #687
NewClassMemberAccess
sniff to detect class member access on instantiation as added in PHP 5.4 and class member access on cloning as added in PHP 7.0. #619. Fixes #53.NewConstantScalarExpressions
sniff to detect PHP 5.6 scalar expression in contexts where PHP previously only allowed static values. #617. Fixes #399.NewGeneratorReturn
sniff to detect return
statements within generators as introduced in PHP 7.0. #618
PCRENewModifiers
sniff to initially detect the new J
regex modifier as introduced in PHP 7.2. #600. Fixes #556.ReservedFunctionNames
sniff to report on double underscore prefixed functions and methods. This was previously reported via an upstream sniff. #581
NewTrailingComma
sniff to detect trailing comma's in function calls, method calls, isset()
and unset()
as will be introduced in PHP 7.3. #632
Upgrade/LowPHPCS
sniff to give users of old PHP_CodeSniffer versions advance warning when support will be dropped in the near future. #693
NewClasses
sniff: check for some 40+ additional PHP native classes added in various PHP versions. #573
NewClosure
sniff: check for usage of self
/parent
/static::
being used within closures, support for which was only added in PHP 5.4. #669. Fixes #668.NewConstants
sniff: recognize constants added by the PHP 5.5+ password extension. #626
NewFunctionParameters
sniff: recognize a number of additional function parameters added in PHP 7.0, 7.1 and 7.2. #602
NewFunctions
sniff: recognize the PHP 5.1 SPL extension functions, the PHP 5.1.1 hash_hmac()
function, the PHP 5.6 pg_lo_truncate()
function, more PHP 7.2 Sodium functions and the new PHP 7.3 is_countable()
function. #606, #625, #640, #651
NewHashAlgorithms
sniff: recognize the new hash algorithms which were added in PHP 7.1. #599
NewInterfaces
sniff: check for the PHP 5.0 Reflector
interface. #572
OptionalRequiredFunctionParameters
sniff: detect missing $salt
parameter in calls to the crypt()
function (PHP 5.6+). #605
RequiredOptionalFunctionParameters
sniff: recognize that the $varname
parameter of getenv()
and the $scale
parameter of bcscale()
have become optional as of PHP 7.1 and 7.3 respectively. #598, #612
AbstractFunctionCallParameterSniff
to be used as a basis for sniffs examining function call parameters. #636
getReturnTypeHintName()
utility method to the PHPCompatibility\Sniff
class. #578, #642
isNumber()
, isPositiveNumber()
and isNegativeNumber()
utility methods to the PHPCompatibility\Sniff
class. #610, #650
isShortList()
utility method to the PHPCompatibility\Sniff
class. #635
getCommandLineData()
method to the PHPCompatibility\PHPCSHelper
class to provide PHPCS cross-version compatible access to command line info at run time. #693
findEndOfStatement()
method to the PHPCompatibility\PHPCSHelper
class to allow for PHPCS cross-version usage of that method. #614
PHPCompatibility\Sniff::isUseOfGlobalConstant()
method handles multi-constant declarations correctly. #587
PHPCompatibility\Sniff::isClassProperty()
method handles multi-property declarations correctly. #583
testVersion
in a custom ruleset to be overruled by the command-line. #607
phpcompatibility/php-compatibility
.getReturnTypeHintToken()
utility method has been made compatible with the changes in the PHPCS tokenizer which were introduced in PHP_CodeSniffer 3.3.0. #642. Fixes #639.ConstantArrayUsingConst
: improved handling of multi-constant declarations. #593
NewHeredocInitialize
: improved handling of constant declarations using the const
keyword.ForbiddenEmptyListAssignment
: this sniff will now also report on empty list assignments when the PHP 7.1 short list syntax is used. #653
ForbiddenNegativeBitshift
sniff would previously only report on "bitshift right". As of this version, "bitshift left" and bitshift assignments will also be recognized. #614
NewClasses
and NewInterfaces
sniffs will now also report on new classes/interfaces when used as return type declarations. #578
NewScalarTypeDeclarations
sniff will now recognize parent
as a valid type declaration.self
and parent
when PHP < 5.2 needs to be supported as PHP 5.1 and lower would presume these to be class names instead of keywords. #595
PregReplaceEModifier
sniff - and the PCRENewModifiers
sniff by extension - will now correctly examine and report on modifiers in regexes passed via calls to preg_replace_callback_array()
. #600, #636
getReturnTypeHintToken()
utility method: improved support for interface methods and abstract function declarations. #652
findExtendedClassName()
, findImplementedInterfaceNames()
, getMethodParameters()
utility methods which are duplicates of upstream PHPCS methods, have been moved from the PHPCompatibility\Sniff
class to the PHPCompatibility\PHPCSHelper
class and have become static methods. #613
getReturnTypeHintToken()
utility method: align returned $stackPtr
with native PHPCS behaviour by returning the last token of the type declaration. #575
getMethodParameters()
method with improved upstream version. #643
MbstringReplaceEModifier
, PregReplaceEModifier
and the PregReplaceEModifier
sniffs now extend
the new AbstractFunctionCallParameterSniff
class. This should yield more accurate results when checking whether one of the target PHP functions was called. #636
DeprecatedNewReference
sniff: minor change to the error text and code - was Forbidden
, now Removed
-. Custom rulesets which explicitly excluded this error code will need to be updated. #594
NewScalarTypeDeclarations
sniff: minor change to the error message text.#644
PHP
. #634
roave/security-advisories
, allowing for PHPUnit 7.x. #604, #616, #622, #646
composer.json
file, validation of the framework specific rulesets. #570, #571, #579, #621, #631
Generic.NamingConventions.CamelCapsFunctionName
. Double underscore prefixed function names are now being reported on by a new dedicated sniff. #581
Generic.NamingConventions.CamelCapsFunctionName
sniff was included in PHPCompatibility. Some error codes of this sniff were excluded, as well as some error messages changed (via the ruleset).ForbiddenNegativeBitshift
sniff would incorrectly throw an error when a bitshift was based on a calculation which included a negative number, but would not necessarily result in a negative number. #614. Fixes #294, #466.NewClosure
sniff would report the same issue twice when the issue was encountered in a nested closure. #669
NewKeywords
sniff would underreport on non-lowercase keywords. #627
NewKeywords
sniff would incorrectly report on the use of class constants and class properties using the same name as a keyword. #627
NewNullableTypes
sniff would potentially underreport when comments where interspersed in the (return) type declarations. #577
Sniff::getFunctionCallParameters()
utility method would in rare cases return incorrect results when it encountered a closure as a parameter. #682
Sniff::getReturnTypeHintToken()
utility method would not always return a $stackPtr
. #645
PHPCompatibility\Tests\BaseClass\MethodTestFrame::getTargetToken()
could potentially not find the correct token to run a test against. #588
Thanks go out to Michael Babker and Juliette Reinders Folmer for their contributions to this version. 👏
Published by wimg almost 7 years ago
See all related issues and PRs in the 8.1.0 milestone.
NewConstants
and RemovedConstants
sniffs to detect usage of new/removed PHP constants for all PHP versions from PHP 5 up. #526, #551, #566. Fixes #263.MagicAutoloadDeprecation
sniff to detect deprecated __autoload()
functions as deprecated in PHP 7.2. #540
OptionalRequiredFunctionParameter
sniff to check for missing function call parameters which were required and only became optional in a later PHP version. #524
DynamicAccessToStatic
sniff to detect dynamic access to static methods and properties, as well as class constants, prior to PHP 5.3. #535. Fixes #534.DeprecatedFunctions
sniff: recognize yet more PHP 7.2 deprecated functions. #561, #566
DeprecatedIniDirectives
sniff: recognize the last of the PHP 7.2 deprecated ini directives. #566, #567
NewFunctions
: detection of all new PHP 7.2 functions added. #522, #545, #551, #565
RemovedExtensions
: report on usage of the mcrypt
extension which has been removed in PHP 7.2. #566
RemovedGlobalVariables
: detection of the use of $php_errormsg
with track_errors
which has been deprecated in PHP 7.2. #528
NewClosures
: downgraded "$this found in closure outside class" to warning. #536. Fixes #527.ForbiddenGlobalVariableVariable
: the sniff will now throw an error for each variable in a global
statement which is no longer supported and show the variable found to make it easier to fix this. Previously only one error would be thrown per global
statement. #564
ForbiddenGlobalVariableVariable
: the sniff will now throw warning
s for non-bare variables used in a global
statement as those are discouraged since PHP 7.0. #564
NewLanguageConstructs
: updated the version number for T_COALESCE_EQUAL
. #523
Sniff::getTestVersion()
: simplified regex logic. #520
FindExtendedClassname()
method with upstream. #507
DealerDirect/phpcodesniffer-composer-installer
Composer plugin has been upped to 0.4.3
. #548
ForbiddenCallTimePassByReference
: a false positive was being thrown when a global constant was followed by a bitwise and. #562. Fixes #39.ForbiddenGlobalVariableVariable
: the sniff was overzealous and would also report on global
in combination with variable variables which are still supported. #564. Fixes #537.ForbiddenGlobalVariableVariable
: variables interspersed with whitespace and/or comments were not being reported. #564
ForbiddenNamesAsInvokedFunctions
: improved recognition of function invocations using forbidden words and prevent warnings for keywords which are no longer forbidden as method names in PHP 7.0+. #516. Fixes #515
VariableVariables
: variables interspersed with whitespace and/or comments were not being reported. #563
Thanks go out to Juliette Reinders Folmer and Jonathan Van Belle for their contributions to this version. 👏
Published by wimg about 7 years ago
See all related issues and PRs in the 8.0.1 milestone.
DeprecatedTypeCasts
sniff to detect deprecated and removed type casts, such as the (unset)
type cast as deprecated in PHP 7.2. #498
NewTypeCasts
sniff to detect type casts not present in older PHP versions such as the (binary)
type cast as added in PHP 5.2.1. #497
NewGroupUseDeclaration
: Detection of PHP 7.2 trailing comma's in group use statements. #504
DeprecatedFunctions
sniff: recognize some more PHP 7.2 deprecated functions. #501
DeprecatedIniDirectives
sniff: recognize more PHP 7.2 deprecated ini directives. #500
ForbiddenNames
sniff: recognize object
as a forbidden keyword since PHP 7.2. #499
NewReturnTypeDeclarations
sniff: recognize generic parent
, PHP 7.1 iterable
and PHP 7.2 object
return type declarations. #505, #499
NewScalarTypeDeclarations
sniff: recognize PHP 7.2 object
type declarion. #499
✏️ Improved clarity of the deprecated functions alternative in the error message. #502
🚒 Temporary hotfix for installed_paths (pending upstream fix.) #503
Thanks go out to Juliette Reinders Folmer for her contributions to this version. 👏
Published by wimg about 7 years ago
IMPORTANT: This release contains a breaking change. Please read the below information carefully before upgrading!
The directory layout of the PHPCompatibility standard has been changed for improved compatibility with Composer.
This means that the PHPCompatibility standard no longer extends from the root directory of the repository, but now lives in its own subdirectory /PHPCompatibility
.
This release also bring compatibility with PHPCS 3.x to the PHPCompatibility standard.
There are two things you will need to be aware of:
phpcs
script has changed (upstream change).Please follow the below upgrade instructions carefully. This should be a one-time only action.
If you had previously made accommodations for the old directory layout, you should remove any such "hacks" (meant in the kindest of ways) now.
By this we mean: symlinks for the PHPCompatibility install to the PHP_CodeSniffer/CodeSniffer/Standards
directory, scripts to move the sniffs files to the PHPCS directory, scripts which made symlinks etc.
So, please remove those first.
Side-note:
If you had previously forked this repository to solve this issue, please consider reverting your fork to the official version or removing it all together.
External PHP CodeSniffer standards need to be registered with PHP CodeSniffer. You have probably done this the first time you used PHPCompatibility or have a script or Composer plugin in place to do this for you.
As the directory layout of PHPCompatibility has changed, the path previously registered with PHP CodeSniffer will no longer work and running phpcs -i
will not list PHPCompatibility as one of the registered standards.
If you use Composer, we recommend you use a Composer plugin to sort this out. In previous install instructions we recommended the SimplyAdmin plugin for this. This plugin has since been abandoned. We now recommend the DealerDirect plugin.
composer remove --dev simplyadmire/composer-plugins
composer require --dev dealerdirect/phpcodesniffer-composer-installer:^0.4.1
composer install
composer update wimg/php-compatibility squizlabs/php_codesniffer
vendor/bin/phpcs -i
If all went well, you should now see PHPCompatibility listed again in the list of installed standards.
First run phpcs --config-show
to check which path(s) are currently registered with PHP CodeSniffer for external standards.
Check in the below table what the new path for PHPCompatibility will be - the path should point to the root directory of your PHPCompatibility install (not to the sub-directory of the same name):
Install type | Old path | New path |
---|---|---|
Composer | vendor/wimg |
vendor/wimg/php-compatibility |
Unzipped release to arbitrary directory | path/to/dir/abovePHPCompatibility |
path/to/dir/abovePHPCompatibility/PHPCompatibility |
Git checkout | path/to/dir/abovePHPCompatibility |
path/to/dir/abovePHPCompatibility/PHPCompatibility |
PEAR | If the old install instruction has been followed, not registered. | path/to/PHPCompatibility |
Side-note:
If you used the old install instructions for a PEAR install, i.e. checking out the latest release to the
PHP/CodeSniffer/Standards/PHPCompatibility
directory, and you intend to upgrade to PHP CodeSniffer 3.x, it is recommended you move the PHPCompatibility folder out of the PEAR directory now, as the layout of the PHPCS directory has changed with PHPCS 3.x and you may otherwise lose your PHPCompatibility install when you upgrade PHP CodeSniffer via PEAR.
There are two ways in which you can register the new installed_paths
value with PHP CodeSniffer. Choose your preferred method:
Run phpcs --config-set installed_paths ...
and include all previously installed paths including the adjusted path for the PHPCompatibility standard.
For example, if the previous value of installed_paths
was
/path/to/MyStandard,/path/to/dir/abovePHPCompatibility
you should now set it using
phpcs --config-set installed_paths /path/to/MyStandard,/path/to/PHPCompatibility
If you use a custom ruleset in combination with PHPCS 2.6.0 or higher, you can pass the value to PHPCS from your custom ruleset:
<config name="installed_paths" value="vendor/wimg/php-compatibility" />
Run phpcs -i
to verify that the PHPCompatibility standard is now listed again in the list of installed standards.
The path to the phpcs
script has changed in PHPCS 3.x which will impact how you call PHPCS.
Version | PHPCS 2.x | PHPCS 3.x |
---|---|---|
Generic phpcs Command |
path/to/PHP_CodeSniffer/scripts/phpcs .... |
path/to/PHP_CodeSniffer/bin/phpcs .... |
Composer command | vendor/bin/phpcs ... |
vendor/bin/phpcs ... |
So, for Composer users, nothing changes. For everyone else, you may want to add the path/to/PHP_CodeSniffer/bin/phpcs
path to your PATH environment variable or adjust any scripts - like build scripts - which call PHPCS.
If you run PHPCompatibility against your code as part of your Travis build:
git clone
to install PHP CodeSniffer and PHPCompatibility on the travis image, your build will fail until you make the following changes:
master
or a PHPCS 3 tag.phpcs --config-set installed_paths
command as described above to point to the root of the cloned PHPCompatibility repo.See all related issues and PRs in the 8.0 milestone.
functionWhitelist
property for the PHPCompatibility.PHP.RemovedExtensions
sniff is now only supported in combination with PHP CodeSniffer 2.6.0 or higher (due to an upstream bug which was fixed in PHPCS 2.6.0). #482
composer.json
file. #446, #482, #486
--prefer-source
or by checking out a git clone of the repository. #494
.dist
extensions or moved for easier access. #478, #479, #483, #493
🚫 Support for PHP 5.1 and 5.2.
The sniffs can now only be run on PHP 5.3 or higher in combination with PHPCS 1.5.6 or 2.x and on PHP 5.4 or higher in combination with PHPCS 3.x. #484, #482
Thanks go out to Gary Jones and Juliette Reinders Folmer for their contributions to this version. 👏
Published by jrfnl about 7 years ago
See all related issues and PRs in the 7.0 milestone.
--runtime-set testVersion 5.0-5.4
will now test your code for compatibility with PHP 5.0 up to PHP 5.4. #99
NewFunctionArrayDereferencing
sniff to detect function array dereferencing as introduced in PHP 5.4. Fixes #52.ShortArray
sniff to detect short array syntax as introduced in PHP 5.4. #97. Fixes #47.TernaryOperators
sniff to detect ternaries without the middle part (elvis
operator) as introduced in PHP 5.3. #101, #103. Fixes #49.ConstantArraysUsingDefine
sniff to detect constants declared using define()
being assigned an array
value which was not allowed prior to PHP 7.0. #110
DeprecatedPHP4StyleConstructors
sniff to detect PHP 4 style class constructor methods which are deprecated as of PHP 7. #109.ForbiddenEmptyListAssignment
sniff to detect empty list() assignments which have been removed in PHP 7.0. #110
ForbiddenFunctionParametersWithSameName
sniff to detect functions declared with multiple same-named parameters which is no longer accepted since PHP 7.0. #110
ForbiddenGlobalVariableVariable
sniff to detect variable variables being made global
which is not allowed since PHP 7.0. #110
ForbiddenNegativeBitshift
sniff to detect bitwise shifts by negative number which will throw an ArithmeticError in PHP 7.0. #110
ForbiddenSwitchWithMultipleDefaultBlocks
sniff to detect switch statements with multiple default blocks which is not allowed since PHP 7.0. #110
NewAnonymousClasses
sniff to detect anonymous classes as introduced in PHP 7.0. #110
NewFunctionParameters
sniff to detect use of new parameters in build-in PHP functions. Initially only sniffing for the new PHP 7.0 function parameters and the new PHP 5.3+ before_needle
parameter for the strstr()
function. #110, #112. Fixes #27.NewGroupUseDeclarations
sniff to detect group use declarations as introduced in PHP 7.0. #110
NewScalarReturnTypeDeclarations
sniff to detect scalar return type hints as introduced in PHP 7.0. #110
NewScalarTypeDeclarations
sniff to detect scalar function parameter type hints as introduced in PHP 7.0. #110
RemovedFunctionParameters
sniff to detect use of removed parameters in build-in PHP functions. Initially only sniffing for the function parameters removed in PHP 7.0. #110
RemovedGlobalVariables
sniff to detect the PHP 7.0 removed $HTTP_RAW_POST_DATA
superglobal. #110
DeprecatedFunctions
sniff: detection of the PHP 5.4 deprecated OCI8 functions. #93
ForbiddenNamesAsInvokedFunctions
sniff: recognize PHP 5.5 finally
as a reserved keywords when invoked as a function. #110
NewKeywords
sniff: detection of the use of the PHP 5.1+ __halt_compiler
keyword. Fixes #50.NewKeywords
sniff: detection of the PHP 5.3+ nowdoc
syntax. Fixes #48.NewKeywords
sniff: detection of the use of the const
keyword outside of a class for PHP < 5.3. Fixes #50.DeprecatedFunctions
sniff: recognize PHP 7.0 deprecated and removed functions. #110
DeprecatedIniDirectives
sniff: recognize PHP 7.0 removed ini directives. #110
ForbiddenNamesAsInvokedFunctions
sniff: recognize new PHP 7.0 reserved keywords when invoked as functions. #110
ForbiddenNames
sniff: recognize new PHP 7.0 reserved keywords. #110
NewFunctions
sniff: recognize new functions as introduced in PHP 7.0. #110
NewLanguageConstructs
sniff: recognize new PHP 7.0 <=>
"spaceship" and ??
null coalescing operators. #110
RemovedExtensions
sniff: recognize PHP 7.0 removed ereg
, mssql
, mysql
and sybase_ct
extensions. #110
NewLanguageConstructs
sniff. #110
testVersion
config variable.DeprecatedIniDirectives
sniff used to always throw an warning
. Now it will throw an error
when a removed ini directive is used. #110.DeprecatedNewReference
sniff will now throw an error when the testVersion
includes PHP 7.0 or higher. #110
ForbiddenNames
sniff now supports detection of reserved keywords when used in combination with PHP 7 anonymous classes. #108, #110.PregReplaceEModifier
sniff will now throw an error when the testVersion
includes PHP 7.0 or higher. #110
NewKeywords
sniff: clarified the error message text for the use
keyword. Fixes #46.testVersion
related utility functions. #98
composer.json
file. #96 Fixes #67.composer.json
file. #75
ForbiddenCallTimePassByReference
sniff was throwing Undefined index
notices when used in combination with PHPCS 2.2.0. #100. Fixes #42.ForbiddenNamesAsInvokedFunctions
sniff would incorrectly throw an error if the throw
keyword was used with parenthesis. Fixes #118.PregReplaceEModifier
sniff incorrectly identified e
's in the pattern as the e
modifier when using {}
bracket delimiters for the regex. #94
RemovedExtensions
sniff was throwing an error
instead of a warning
for deprecated, but not (yet) removed extensions. Fixes #62.Thanks go out to AlexMiroshnikov, Chris Abernethy, dgudgeon, djaenecke, Eugene Maslovich, Ken Guest, Koen Eelen, Komarov Alexey, Mark Clements and Remko van Bezooijen for their contributions to this version. 👏
Published by wimg over 7 years ago
NewKeywords
sniff will now also sniff for yield from
which was introduced in PHP 7.0. #477. Fixes #476
NewExecutionDirectives
sniff will now also report on execution directives when used in combination with PHPCS 2.0.0-2.3.3. #451
getMethodParameters()
utility method will no longer break when used with PHPCS 1.5.x < 1.5.6. This affected a number of sniffs. #452
inUseScope()
utility method will no longer break when used with PHPCS 2.0.0 - 2.2.0. This affected a number of sniffs. #454
DefaultTimeZoneRequired
sniff. This sniff was checking server settings rather than code. #458. Fixes #457
NewMagicClassConstant
sniff as introduced in v 7.1.4 contained two additional checks for not strictly compatibility related issues. One of these was plainly wrong, the other opinionated. Both have been removed. #442. Fixes #436
NewClass
sniff: was reporting an incorrect introduction version number for a few of the Exception classes. #441. Fixes #440.ForbiddenBreakContinueVariableArguments
sniff: was incorrectly reporting an error if the break
or continue
was followed by a PHP closing tag (breaking out of PHP). #462. Fixes #460
ForbiddenGlobalVariableVariable
sniff: was incorrectly reporting an error if the global
statement was followed by a PHP closing tag (breaking out of PHP). #463.DeprecatedFunctions
sniff: was reporting false positives for classes using the same name as a deprecated function. #465. Fixes #464
Thanks go out to Juliette Reinders Folmer and Mark Clements for their contributions to this version. 👏
Published by wimg over 7 years ago
CaseSensitiveKeywords
sniff to detect use of non-lowercase self
, static
and parent
keywords which could cause compatibility issues pre-PHP 5.5. #382
ConstantArraysUsingConst
sniff to detect constants defined using the const
keyword being assigned an array value which was not supported prior to PHP 5.6. #397
ForbiddenClosureUseVariableNames
sniff to detect PHP 7.1 forbidden variable names in closure use statements. #386. Fixes #374
NewArrayStringDereferencing
sniff to detect array and string literal dereferencing as introduced in PHP 5.5. #388
NewHeredocInitialize
sniff to detect initialization of static variables and class properties/constants using the heredoc syntax which is supported since PHP 5.3. #391. Fixes #51
NewMagicClassConstant
sniff to detect use of the magic ::class
constant as introduced in PHP 5.5. #403. Fixes #364.NewUseConstFunction
sniff to detect use statements importing constants and functions as introduced in PHP 5.6. #401
DeprecatedFunctions
sniff: recognize PHP 7.2 deprecated GD functions. #392
DeprecatedIniDirectives
sniff: recognize PHP 7.2 deprecated mbstring.func_overload
directive. #377
NewClasses
sniff: check for the PHP 5.1 libXMLError
class. #412
NewClasses
sniff: recognize all native PHP Exception classes. #418
NewClosures
sniff: check for closures being declared as static and closures using $this
. Both of which was not supported pre-PHP 5.4. #389. Fixes #24.NewFunctionParameters
sniff: recognize new exclude_disabled
parameter for the get_defined_functions()
function as introduced in PHP 7.0.15. #375
NewFunctions
sniff: recognize new PHP 7.2 socket related functions. #376
NewInterfaces
sniff: check for some more PHP native interfaces. #411
isClassProperty()
, isClassConstant()
and validDirectScope()
utility methods to the PHPCompatibility_Sniff
class. #393, #391.getTypeHintsFromFunctionDeclaration()
utility method to the PHPCompatibility_Sniff
class. #414.NewMagicMethods
sniff. #381
getTestVersion()
utility method. #405, #430
installed_paths
via a custom ruleset. #407
Changelog.md
file containing a record of notable changes since the first tagged release. #421
ForbiddenNamesAsDeclared
sniff will now emit warning
s for soft reserved keywords. #406, #370.ForbiddenNames
sniff will now allow for the more liberal rules for usage of reserved keywords as of PHP 7.0. #417
InternalInterfaces
, NewClasses
, NewConstVisibility
, NewInterfaces
, NewMagicMethods
, NonStaticMagicMethods
and RemovedGlobalVariables
sniffs will now also sniff for and correctly report violations in combination with anonymous classes. #378, #383, #393, #394, #395, #396. Fixes #351 and #333.NewClasses
and NewInterfaces
sniffs will now also report on new classes/interfaces when used as type hints. #414, #416. Fixes #352
NewClasses
sniff will now also report on Exception classes when used in (multi-)catch
statements. #418. Fixes #373.NewScalarTypeDeclarations
sniff will now report on new type hints even when the type hint is nullable. #379
NewNowdoc
sniff has been renamed to NewNowdocQuotedHeredoc
and will now also check for double quoted heredoc identifiers as introduced in PHP 5.3. #390
NewClasses
sniff will now also report anonymous classes which extend
a new sniff when used in combination with PHPCS 2.4.0-2.8.0. #432. Fixes #334.NewFunctionParameter
sniff: version number precision for two parameters. #384, #428
ForbiddenClosureUseVariable
sniff when run on PHPCS 2.5.1 as these cause an infinite loop due to an upstream bug. #408
trait
s in combination with PHP < 5.4 and PHPCS < 2.4.0 as trait
s are not recognized in those circumstances. #431
testVersion
resulted in unreported errors when used with sniffs using the supportsBelow()
method. This affected the results of approximately half the sniffs. #430
ForbiddenNames
sniff would throw false positives for use
statements with the final
modifier in traits. #402.ForbiddenNames
sniff would fail to report on functions declared to return by reference using a reserved keyword as the function name. #413
ForbiddenNames
sniff would only examine the first part of a namespace and not report on reserved keywords used in subsequent parts of a nested namespace. #419
ForbiddenNames
sniff would not always correctly report on use statements importing constants or functions using reserved keywords. #420
NewKeywords
sniff would sometimes fail to report on the const
keyword when used in a class, but not for a class constant. #424
master
branch to reflect this. This was causing the builds to fail. #422
Thanks go out to Juliette Reinders Folmer and Mark Clements for their contributions to this version. 👏
Published by wimg over 7 years ago
Several updates for 7.1 (and some for 7.2)
See all related issues and PRs in the 7.1.3 milestone.
testVersion
config parameter now allows for specifying unbounded ranges.-5.6
means: check for compatibility with all PHP versions up to and including PHP 5.6;7.0-
means: check for compatibility with all PHP versions from PHP 7.0 upwards.testVersion
, see Using the compatibility sniffs in the readme.ShortArray
sniff. #347
supportsBelow()
, supportsAbove()
and getTestVersion()
utility methods. #363
Contributing.md
file with information about reporting bugs, requesting features, making pull requests and running the unit tests. #350
ForbiddenFunctionParametersWithSameName
, NewScalarTypeDeclarations
, ParameterShadowSuperGlobals
sniff will now also sniff for and report violations in closures. #331
nowdoc
structure has been moved from the NewKeywords
sniff to a new stand-alone NewNowdoc
sniff which will now also recognize this structure when the sniffs are run on PHP 5.2. #335
ForbiddenNames
sniff will now also correctly recognize reserved keywords used in a declared namespace when run on PHP 5.2. #362
testVersion
settings and makes the unit tests run ~6 x faster.LongArrays
sniff. The checks it contained have been moved into the RemovedGlobalVariables
sniff. Both sniffs essentially did the same thing, just for different PHP native superglobals. #354
PregReplaceEModifier
sniff would throw a false positive if a quote character was used as the regex delimiter. #357
RemovedGlobalVariables
sniff would report false positives for class properties shadowing the removed $HTTP_RAW_POST_DATA
variables. #354.getFQClassNameFromNewToken()
utility function could go into an infinite loop causing PHP to run out of memory when examining unfinished code (examination during live coding). #338, #342
determineNamespace()
utility method would in certain cases not break out a loop. #358
Thanks go out to Arthur Edamov, Juliette Reinders Folmer, Mark Clements and Tadas Juozapaitis for their contributions to this version. 👏
Published by wimg over 7 years ago
Several updates for 7.1 (and some for 7.2)
See all related issues and PRs in the 7.1.2 milestone.
VariableVariables
sniff to detect variables variables for which the behaviour has changed in PHP 7.0. #310 Fixes #309.NewReturnTypeDeclarations
sniff will now also sniff for non-scalar return type declarations, i.e. array
, callable
, self
or a class name. #323
NewLanguageConstructs
sniff will now also sniff for the null coalesce equal operator ??=
. This operator is slated to be introduced in PHP 7.2 and PHPCS already accounts for it. #340
getReturnTypeHintToken()
utility method to the PHPCompatibility_Sniff
class to retrieve return type hints from function declarations in a cross-PHPCS-version compatible way. #323.stripVariables()
utility method to the PHPCompatibility_Sniff
class to strip variables from interpolated text strings. #341.MbstringReplaceEModifier
, PregReplaceEModifier
and NewExecutionDirectives
sniffs will now also correctly interpret double quoted text strings with interpolated variables. #341, #324.NewNullableTypes
sniff will now also report on nullable (return) type hints when used with closures. #323
NewReturnTypeDeclarations
sniff will now also report on return type hints when used with closures. #323
inClassScope()
utility method. #315
NewScalarReturnTypeDeclarations
sniff has been renamed to NewReturnTypeDeclarations
. #323
ForbiddenNames
sniff will now also correctly ignore anonymous classes when used in combination with PHPCS < 2.3.4. #319
NewAnonymousClasses
sniff will now correctly recognize and report on anonymous classes when used in combination with PHPCS < 2.5.2. #325
NewGroupUseDeclarations
sniff will now correctly recognize and report on group use statements when used in combination with PHPCS < 2.6.0. #320
NewNullableTypes
sniff will now correctly recognize and report on nullable return types when used in combination with PHPCS < 2.6.0. #323
NewReturnTypeDeclarations
sniff will now correctly recognize and report on new return types when used in combination with PHPCS < 2.6.0. #323
hasCondition()
utility method where appropriate. #315
@group
annotations allowing for quicker/easier testing of a select group of tests/sniffs. #305
@covers
annotations to improve code coverage reporting and remove bleed through of accidental coverage. #307
ConstantArraysUsingDefine
sniff would throw false positives if the value of the define()
was retrieved via a function call and an array parameter was passed. #327
ForbiddenCallTimePassByReference
sniff would throw false positives on assign by reference within function calls or conditions. #302 Fixes the last two cases reported in #68
ForbiddenGlobalVariableVariableSniff
sniff would only examine the first variable in a global ...
statement causing unreported issues if subsequent variables were variable variables. #316
NewKeywords
sniff would throw a false positive for the const
keyword when encountered in an interface. #312
NewNullableTypes
sniff would not report on nullable return types for namespaced classnames used as a type hint. #323
PregReplaceEModifier
sniff would always consider the first parameter passed as a single regex, while it could also be an array of regexes. This led to false positives and potentially unreported use of the e
modifier when an array of regexes was passed. #300
PregReplaceEModifier
sniff could misidentify the regex delimiter when the regex to be examined was concatenated together from various text strings taken from a compound parameter leading to false positives. #300
Thanks go out to Juliette Reinders Folmer for her contributions to this version. 👏
Published by wimg almost 8 years ago
All deprecations, new features, etc. for PHP 7.1
See all related issues and PRs in the 7.1.1 milestone.
ForbiddenNamesAsDeclared
sniff: detection of the PHP 7.1 iterable
and void
reserved keywords when used to name classes, interfaces or traits. #298
ForbiddenNamesAsInvokedFunctions
sniff would incorrectly throw an error if the clone
keyword was used with parenthesis. #299. Fixes #284
Thanks go out to Juliette Reinders Folmer for her contributions to this version. 👏