1.2.137. Class Function Confusion¶
Avoid classes and functions bearing the same name.
When functions and classes bear the same name, calling them may be confusing. This may also lead to forgotten ‘new’ keyword.
<?php
class foo {}
function foo() {}
// Forgetting the 'new' operator is easy
$object = new foo();
$object = foo();
?>
1.2.137.1. Connex PHP features¶
1.2.137.1.1. Suggestions¶
Use a naming convention to distinguish functions and classes
Rename the class or the function (or both)
Use an alias with a use expression
1.2.137.1.2. Specs¶
Short name |
Php/ClassFunctionConfusion |
Rulesets |
|
Exakat since |
0.10.2 |
PHP Version |
All |
Severity |
Minor |
Time To Fix |
Slow (1 hour) |
Precision |
Very high |
Available in |