0
类日志记录{   

    私人 $log_file = 'c:/xampp/htdocs/jcert2/tmp/sslogfile.txt';   
    公共静态 $fp = null;

    公共静态函数 lwrite($message){   
    if (Logging::fp) 记录::lopen();   
  // $script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);   
    $time = date('H:i:s');   
    fwrite(Logging::fp, "$time $message\n");   
  }   
  // 打开日志文件   
  私有静态函数 lopen(){   
    $lfile = $this->log_file;   
    $today = date('Ymd');   
    Logging::fp = fopen($lfile . '_' . $today, 'a') 或 exit("无法打开 $lfile!");   
  }   
}  

我创建了一个日志文件,最后一行出现错误

记录::fp = fopen(....)
错误是意外的'='有人可以指导我理解和纠正错误。

4

3 回答 3

0

双冒号表示类的静态属性。您不能为类的静态属性赋值。有关静态属性的更多信息,请参阅:

http://php.net/manual/en/language.oop5.static.php

于 2012-07-25T05:22:53.287 回答
0

缺少 $: Logging::$fp = fopen($lfile . '_' . $today, 'a') 或 exit("Can't open $lfile!");

于 2012-07-25T05:28:27.397 回答
0

您可以使用 getter/setter

class Logging{   

    private $log_file = 'c:/xampp/htdocs/jcert2/tmp/sslogfile.txt';   
    private $fp = null;

    private static function lopen(){   
        $lfile = $this->log_file;   
        $today = date('Y-m-d');   
        $this->fp = fopen($lfile . '_' . $today, 'a') or exit("Can't open $lfile!");   
    }

    public static function get_fp(){
        return $this->fp;
    }
}  
于 2012-07-25T07:34:08.330 回答