if语句中的php static

Ald*_*ein 9 php static if-statement variable-declaration

我的配置文件中有这样的结构:

<?php
if (true) {
    $nonstatic = 1;
    static $config = 1;
}
else {
    $nonstatic = 2;
    static $config = 2;
}

echo $nonstatic;
echo $config;
?>
Run Code Online (Sandbox Code Playgroud)

那么为什么$ config包含2如果该部分语句为false且$ nonstatic包含1?这是一个错误吗?

Mau*_*nRa 11

我想这个块是从函数中包含的.

静态变量的初始化在编译时解析,如果解释器找到多个初始化,则它只取底部.