簡體   English   中英

我編寫的php代碼錯誤無法理解如何糾正?

[英]Error in php code I have written unable to understand how to correct it?

class Logging{   

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

    public static function lwrite($message){   
    if (Logging::fp) Logging::lopen();   
  //  $script_name = pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME);   
    $time = date('H:i:s');   
    fwrite(Logging::fp, "$time $message\n");   
  }   
  // open log file   
  private static function lopen(){   
    $lfile = $this->log_file;   
    $today = date('Y-m-d');   
    Logging::fp = fopen($lfile . '_' . $today, 'a') or exit("Can't open $lfile!");   
  }   
}

我創建了一個日志文件,最后一行出現錯誤

Logging::fp = fopen(....)
錯誤是意外錯誤'='可以指導我理解和糾正錯誤。

雙冒號表示該類的靜態屬性。 您不能將值分配給類的靜態屬性。 有關靜態屬性的更多信息,請參見:

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

缺少$:Logging :: $ fp = fopen($ lfile。'_'。$ today,'a')或exit(“無法打開$ lfile!”);

您可以使用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;
    }
}  

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM