1.2.135. 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.135.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.135.2. Specs

Short name

Php/ClassFunctionConfusion

Rulesets

All, Changed Behavior, Semantics

Exakat since

0.10.2

PHP Version

All

Severity

Minor

Time To Fix

Slow (1 hour)

Precision

Very high

Features

function, class

Available in

Entreprise Edition, Exakat Cloud