1.2.1160. Static Variable Initialisation¶
Static variables can be initialized like any other variable, straight from the static
keyword. This was added in PHP 8.3.
Indeed, static variables are variables, so they shall be initialized with any value, another variable or a functioncall. This behavior is different from the static constant expression, where only a small set of operators and constants can be used.
<?php
function foo(int $a = 0) {
static $s = 1;
static $s2 = $a + 1;
}
?>
1.2.1160.1. Connex PHP features¶
1.2.1160.1.1. Specs¶
Short name |
Variables/StaticVariableInitialisation |
Rulesets |
All, Changed Behavior, CompatibilityPHP81, CompatibilityPHP82 |
Exakat since |
2.6.1 |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Available in |