1.2.1021. Redeclared Static Variable¶
Static variables shall be declared only once. It is forbidden in PHP 8.3 and later. It was silently allowed in PHP 8.2 and older.
<?php
function foo() {
static $a;
static $a;
}
?>
1.2.1021.1. Suggestions¶
Keep the last static call
Keep the first static call
1.2.1021.2. Specs¶
Short name |
Variables/RedeclaredStaticVariable |
Rulesets |
All, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, CompatibilityPHP81, CompatibilityPHP82 |
Exakat since |
2.5.3 |
Severity |
Major |
Time To Fix |
Instant (5 mins) |
Precision |
Very high |
Features |
static-variable |
Available in |