1.2.1152. Static Variables

In PHP, variables may be static. They will survive after the function execution end, and will be available at the next function run. They are distinct from globals, which are available application wide, and from static properties, which are tied to a class of objects.

<?php

function foo() {
    // static variable
    static $count = 0;

    echo ++$count;
}

class bar {
    // This is not a static variable :
    // it is a static property
    static $property = 1;
}

?>

See also Using static variables.

1.2.1152.1. Specs

Short name

Variables/StaticVariables

Rulesets

All, Appinfo, CE

Exakat since

0.8.4

PHP Version

All

Severity

Minor

Time To Fix

Quick (30 mins)

Precision

Very high

Features

static-variable

Available in

Entreprise Edition, Community Edition, Exakat Cloud