Components Sniffs Features
October 1, 2020 at 2:12 AMSniffs
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 |
| 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 | Contant 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 |
| Keywords | ReservedSniff | Scalar type declarations |
| FunctionDeclarations | ReturnTypeDeclarationSniff | Return 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 |
|---|---|---|
PHP 7.4
| Sniff category | Sniff class name | PHP Feature |
|---|---|---|
| Classes | TypedPropertySniff | Typed properties |
VersionResolverVisitor |
Arrow functions |
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
VersionResolverVisitorand keywords (this, self, parent, static) are detected withClosureSniff -
Arrow functions have no sniff, because its detected by the
VersionResolverVisitor, but has its test case withArrowFunctionSniffTest