1.2.526. Hidden Use Expression

The use expression for namespaces should always be at the beginning of the namespace block.

It is where everyone expect them, and it is less confusing than having them at various levels.

<?php

// This is visible
use A;

class B {}

// This is hidden
use C as D;

class E extends D {
    use traitT; // This is a use for a trait

    function foo() {
        // This is a use for a closure
        return function ($a) use ($b) {}
    }
}

?>

1.2.526.1. Suggestions

  • Group all uses together, at the beginning of the namespace or class

1.2.526.2. Specs

Short name

Namespaces/HiddenUse

Rulesets

All, Analyze, CE, CI-checks, Changed Behavior

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Instant (5 mins)

Precision

High

Features

use

Examples

Tikiwiki, OpenEMR

Available in

Entreprise Edition, Community Edition, Exakat Cloud