1.2.382. Don’t Use The Type As Variable Name

When it is difficult to find a good name, it is very tempting to use the type.

Such a name should carry its actual usage, as the type is already hold by the data.

This rule check for parameters and variables which uses the type as name. It also report instantiation which hold the same name than the instantiated class.

<?php

$sqlite3 = new Sqlite3();

function foo(int $int) : array {
     $array = [];
     return $array;
}
?>

1.2.382.1. Connex PHP features

1.2.382.1.1. Suggestions

  • Use another name than the class or the type

1.2.382.1.2. Specs

Short name

Structures/DontUseTheTypeAsVariable

Rulesets

All, Changed Behavior, Semantics

Exakat since

2.6.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

High

Available in

Entreprise Edition, Exakat Cloud