1.2.1149. Static Variable Can Default To Arbitrary Expression¶
Static variables can hold any type of PHP expression. Indeed, those are variables, so their value can be build from other variables, and even functioncalls.
This feature was introduced in PHP 8.3.
<?php
function foo($init) {
static $variable = foo($a);
return $variable++;
}
?>
1.2.1149.1. Specs¶
Short name |
Php/StaticVariableDefaultCanBeAnyExpression |
Rulesets |
All, Changed Behavior, CompatibilityPHP53, CompatibilityPHP54, CompatibilityPHP55, CompatibilityPHP56, CompatibilityPHP70, CompatibilityPHP71, CompatibilityPHP72, CompatibilityPHP73, CompatibilityPHP74, CompatibilityPHP80, CompatibilityPHP81, CompatibilityPHP82 |
Exakat since |
2.5.3 |
PHP Version |
With PHP 8.3 and more recent |
Severity |
Minor |
Time To Fix |
Quick (30 mins) |
Precision |
Very high |
Features |
static-variable |
Available in |