1.2.1149. Static Global Variables Confusion

PHP can’t have variable that are both static and global variable. While the syntax is legit, the variables will be alternatively global or static.

It is recommended to avoid using the same name for a global variable and a static variable.

<?php

function foo() {
    $a = 1; // $a is a local variable

    global $a; // $a is now a global variable

    static $a; // $a is not w static variable
}

?>

1.2.1149.1. Connex PHP features

1.2.1149.1.1. Suggestions

  • Avoid using static variables

  • Avoid using global variables

  • Avoid using the same name for static and global variables

1.2.1149.1.2. Specs

Short name

Structures/SGVariablesConfusion

Rulesets

All, Changed Behavior, Semantics, Suggestions

Exakat since

2.1.2

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Available in

Entreprise Edition, Exakat Cloud