if语句中的php静态

标签 php static if-statement variable-declaration

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

<?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/

相关文章:

php - 缩放灯

php - 当表格中的一行不适合页面时,如何在 TCPDF 上设置自动分页符?

php - stub 单个函数 - 不涉及类 - php

java - 非静态变量的引用

c - PowerPC 程序集中的 "ifdef"

python - 使用 'for' 或 'if' 条件在 Python 中创建 CSV 文件

if-statement - 带有 if_match 和 'and' 的 conky

php - 正则表达式可选组和数字长度

PHP 通过引用返回静态变量

c++ - 为什么在c++中禁止静态分配?