PHP静态变量赋值需要注意!
<?php
function foo(){
static $int = 0; // correct
static $int = 1+2; // correct
static $int = sqrt(121); // wrong (as it is a function)
$int++;
echo $int;
}
?>
常量表达式的结果可以赋值给静态变量,但是动态表达式(比如函数调用)会导致解析错误。因为静态声明是在编译时解析的。
暂无标签