I have a construction like this in my config file:
<?php
if (true) {
$nonstatic = 1;
static $config = 1;
}
else {
$nonstatic = 2;
static $config = 2;
}
echo $nonstatic;
echo $config;
?>
So why the $config contains 2 if this part of the statement is false and $nonstatic contains 1? Is it开发者_如何学Python a bug?
I suppose this chunk is being included from a function.
Initialisations of static variables are resolved at compile-time, and if the interpreter finds multiple initialisations, it simply takes the bottom one.
精彩评论