PHP为什么不能将静态变量初始化为time()?

时间:2015-05-01 15:53:55

标签: static initialization

将静态变量初始值设置为time()时收到错误。

错误消息是" 语法错误,意外'(',期待','或&#39 ;;&#39 ;在第7行的 [...] [...] "

<?php 
define("DEBUG", true);
define("NEWLINE", "<br>");
...
function debugMsg($msg) {
    static $lastTime = time();
    if(DEBUG==true) echo date('Y-m-d H:i:s', time())." ".$msg." (".(time()-$lastTime)." seconds)".NEWLINE;
    $lastTime = time();
}
?>

debugMsg("XXX task completed");
//My expected output like below:
//2015-05-01 15:04:47 XXX task completed (2 seconds) 

0 个答案:

没有答案