1.2.895. Order Of Declaration¶
The order used to declare members and methods has a great impact on readability and maintenance. However, practices varies greatly. As usual, being consistent is the most important and useful.
The suggested order is the following : traits, constants, properties, methods. Optional characteristics, like final, static… are not specified. Special methods names are not specified.
<?php
class x {
use traits;
const CONSTANTS = 1;
const CONSTANTS2 = 1;
const CONSTANTS3 = 1;
private $property = 2;
private $property2 = 2;
private $property3 = 2;
public function foo() {}
public function foo2() {}
public function foo3() {}
public function foo4() {}
}
?>
1.2.895.1. Connex PHP features¶
1.2.895.1.1. Suggestions¶
Always declare class elements (traits, constants, properties, methods) in the same order.
1.2.895.1.2. Specs¶
Short name |
Classes/OrderOfDeclaration |
Rulesets |
|
Exakat since |
0.11.7 |
PHP Version |
All |
Severity |
|
Time To Fix |
|
Precision |
Medium |
Available in |