1.2.246. Could Be A Static Variable

This global is only used in one function or method. It may be transformed into a ‘static’ variable, instead of global. This allows you to keep the value between call to the function, but will not be accessible outside this function.

<?php
function foo( ) {
    static $variableIsReservedForX; // only accessible within foo( ), even between calls.
    global $variableIsGlobal;       //      accessible everywhere in the application
}
?>

1.2.246.1. Specs

Short name

Structures/CouldBeStatic

Rulesets

All, Analyze, Changed Behavior, Class Review

Exakat since

0.8.4

PHP Version

All

Severity

Major

Time To Fix

Quick (30 mins)

Precision

Very high

Features

static, static-variable

Examples

Dolphin, Contao

Available in

Entreprise Edition, Exakat Cloud