I'm writing a simple class that will create a simple log file for my site. For some reason, when I have variable file_path outside of the function, I get this error...
Parse error: parse error, expecting `','' or `';''
With this code..
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";
}
}
However when the variable is within the function, this error doesn't come. Why is this?
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";
}