1.2.1150. Static Variable In Namespace

Static variables may be declared outside a function scope, but it has no usage. Static variables are persistent between function calls, and there is not such thing as namespace call (including an ‘include’ call).

<?php

namespace A {
     // Static has no value here.
     static $a = 1;

     function foo() {
             // One useful static variable
             static $static = 2;
     }
}

?>

1.2.1150.1. Suggestions

  • Remove the ‘static’ keyword in the code

1.2.1150.2. Specs

Short name

Variables/StaticVariableInNamespace

Rulesets

All, Dead code

Exakat since

2.6.1

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

static-variable, namespace

Available in

Entreprise Edition, Exakat Cloud