サイトの単純なログ ファイルを作成する単純なクラスを作成しています。何らかの理由で、関数の外に変数 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";
}