Skip to content

Sniffs

Before version 5.4, PHP CompatInfo and its compatibility analyser was monolithic code.

Since version 5.4, PHP CompatInfo used a sniff architecture that simplify maintainability of existing code and allows to extend it more easily.

Each sniff, is in charge to detect a PHP language feature. Here is the list of features supported and their corresponding sniffs :

PHP 5.0

Sniff category Sniff class name PHP Feature
Classes MethodDeclarationSniff Method Visibility
Classes PropertyDeclarationSniff Properties

PHP 5.1

Sniff category Sniff class name PHP Feature
Classes MagicMethodsSniff Magic Methods

PHP 5.2

Sniff category Sniff class name PHP Feature

PHP 5.3

Sniff category Sniff class name PHP Feature
Classes MagicMethodsSniff Magic Methods
Classes DynamicAccessSniff Dynamic Static Method access
Classes DynamicAccessSniff Dynamic Static Property access
ControlStructures DeclareSniff Declare
ControlStructures GotoSniff Goto
FunctionDeclarations ClosureSniff Anonymous functions
VersionResolverVisitor Closures
Operators ShortTernaryOperatorSniff Ternary Operator
VersionResolverVisitor Namespaces
TextProcessing CryptStringSniff CRYPT_BLOWFISH security fix details

PHP 5.4

Sniff category Sniff class name PHP Feature
Arrays ArrayDereferencingSyntaxSniff Array dereferencing
Arrays ShortArraySyntaxSniff Short array syntax
Classes ClassMemberAccessSniff Class member access on instantiation
Expressions ClassExprSyntaxSniff Class::{expr}() syntax
Numbers BinaryNumberFormatSniff Binary number format
UseDeclarations UseTraitSniff Traits
VersionResolverVisitor Traits

PHP 5.5

Sniff category Sniff class name PHP Feature
Constants MagicClassConstantSniff ::class syntax
Expressions EmptySniff empty() supports arbitrary expressions
Generators GeneratorSniff Generators

PHP 5.6

Sniff category Sniff class name PHP Feature
Classes MagicMethodsSniff Magic Methods
Constants ConstSyntaxSniff Constant Expressions
Operators PowOperatorSniff Exponentiation
UseDeclarations UseConstFunctionSniff use function and use const

PHP 7.0

Sniff category Sniff class name PHP Feature
FunctionDeclarations ParamTypeDeclarationSniff Scalar type declarations
FunctionDeclarations ReturnTypeDeclarationSniff Return type declarations
Keywords ReservedSniff Scalar type declarations
Operators NullCoalesceOperatorSniff Null coalescing operator
Operators CombinedComparisonOperatorSniff Spaceship operator
Constant arrays using define()
Classes AnonymousClassSniff Anonymous classes
Classes ClassMemberAccessSniff Class member access on cloning
ControlStructures DeclareSniff Declare
Generators GeneratorSniff Generator Return Expressions
Generators GeneratorSniff Generator Delegation

PHP 7.1

Sniff category Sniff class name PHP Feature
FunctionDeclarations ParamTypeDeclarationSniff Nullable types
FunctionDeclarations ReturnTypeDeclarationSniff Nullable types
FunctionDeclarations ReturnTypeDeclarationSniff Void functions
Symmetric array destructuring
Class constant visibility
FunctionDeclarations ParamTypeDeclarationSniff iterable pseudo-type
Keywords ReservedSniff iterable pseudo-type
Multi catch exception handling
Support for keys in list()

PHP 7.2

Sniff category Sniff class name PHP Feature
Keywords ReservedSniff New object type

PHP 7.3

Sniff category Sniff class name PHP Feature
FunctionCalls SameSiteCookieSniff SetCookie accept $options argument

PHP 7.4

Sniff category Sniff class name PHP Feature
Arrays ArrayUnpackingSyntaxSniff Array unpacking support for numeric-keyed arrays
Classes TypedPropertySniff Typed properties
FunctionDeclarations ArrowFunctionSniff Arrow functions
VersionResolverVisitor Arrow functions

PHP 8.0

Sniff category Sniff class name PHP Feature
Attributes AttributeSniff Attributes
Classes PropertyPromotionSniff Constructor property promotion
ControlStructures MatchSniff Match expressions
ControlStructures NonCapturingCatchSniff Non-capturing catches
FunctionDeclarations NamedArgumentDeclarationSniff Named arguments
FunctionDeclarations ParamTypeDeclarationSniff Union types
FunctionDeclarations TrailingCommaSniff Trailing comma
Operators NullsafeOperatorSniff Nullsafe operator

PHP 8.1

Sniff category Sniff class name PHP Feature
Arrays ArrayUnpackingSyntaxSniff Array unpacking support for string-keyed arrays
Classes ReadonlyPropertySniff Readonly Properties
Classes NewInitializerSniff New initializers
Constants ClassConstantSniff Final class constants
Enumerations EnumerationSniff Enumerations
Fibers FiberSniff Fibers
FunctionDeclarations FirstClassCallableSniff First class callable
FunctionDeclarations ParamTypeDeclarationSniff Pure Intersection Types
FunctionDeclarations ReturnTypeDeclarationSniff Pure Intersection Types
FunctionDeclarations ReturnTypeDeclarationSniff Never return type
Numbers OctalNumberFormatSniff Explicit Octal numeral notation

PHP 8.2

Sniff category Sniff class name PHP Feature
Attributes AllowDynamicPropertiesAttributeSniff AllowDynamicProperties attribute
Attributes SensitiveParameterAttributeSniff SensitiveParameter attribute
Classes ReadonlyClassSniff Readonly Classes
Constants ConstantsInTraitsSniff Constants in Traits
FunctionDeclarations ParamTypeDeclarationSniff Disjunctive Normal Form Types
FunctionDeclarations ReturnTypeDeclarationSniff Allow null, false, and true as stand-alone types
TextProcessing DeprecateDollarBraceStringInterpolationSniff Deprecated \${} string interpolation

PHP 8.3

Sniff category Sniff class name PHP Feature
Attributes OverrideAttributeSniff Override attribute
Constants DynamicClassConstantFetchSniff Dynamic Class Constant fetch syntax
Constants TypedClassConstantSniff Typed Class Constants
Expressions StaticVarInitializerSniff Static Variable initializers

Special cases

  • Namespaces declaration have no sniff, because its detected by the VersionResolverVisitor
  • Classes declaration have no sniff, because its detected by the VersionResolverVisitor
  • Interfaces declaration have no sniff, because its detected by the VersionResolverVisitor
  • Traits declaration have no sniff, because its detected by the VersionResolverVisitor
  • Closures are initialized by the VersionResolverVisitor and keywords (this, self, parent, static) are detected with ClosureSniff
  • Arrow functions have no sniff, because its detected by the VersionResolverVisitor, but has its test case with ArrowFunctionSniffTest