Reputation: 30187
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!"); } }
I have created a logging file and i am getting an error in last line
Logging::fp = fopen(....)the error is unexpected '=' can somebody guide me in understanding and rectifying the error.
Upvotes: 0
Views: 76
Reputation: 2339
You can use getters/setters
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;
}
}
Upvotes: 0
Reputation: 546
Missing $: Logging::$fp = fopen($lfile . '_' . $today, 'a') or exit("Can't open $lfile!");
Upvotes: 0
Reputation: 4288
The double colon indicates a static property of the class. You cannot assign values to static properties of a class. For more on static properties, see :
http://php.net/manual/en/language.oop5.static.php
Upvotes: 0