开发者

php static in if statement

开发者 https://www.devze.com 2023-04-04 09:26 出处:网络
I have a construction like this in my config file: <?php if (true) { $nonstatic = 1; static $config = 1;

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消