我正在编写一个简单的类,它将为我的站点创建一个简单的日志文件。出于某种原因,当我在函数之外有变量 file_path 时,我得到了这个错误......
Parse error: parse error, expecting `','' or `';''
有了这个代码..
class Logger {
public $file_path = SITE_ROOT.DS.'logs'.DS.'log.txt';
public static function log_action ($message="") {
if (file_exists($file_path)) {
file_put_contents($file_path, $message, FILE_APPEND);
} else {
return "could not write to log file";
}
}
但是,当变量在函数内时,不会出现此错误。为什么是这样?
public static function log_action ($action, $message="") {
$file_path = SITE_ROOT.DS.'logs'.DS.'log.txt';
if (file_exists($file_path)) {
file_put_contents($file_path, $message, FILE_APPEND);
} else {
return "could not write to log file";
}