我的配置文件中有这样的结构:
<?php
if (true) {
$nonstatic = 1;
static $config = 1;
}
else {
$nonstatic = 2;
static $config = 2;
}
echo $nonstatic;
echo $config;
?>
那么,如果这部分语句为假而 $nonstatic 包含 1,那么为什么 $config 包含 2?是错误吗?
最佳答案
我想这个 block 是从一个函数中包含的。
静态变量的初始化在编译时解决,并且 if the interpreter finds multiple initialisations, it simply takes the bottom one .
关于if语句中的php静态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7404989/