Jump to content

Automatically setting static attributes... is this the only way to do it?


sfc

Recommended Posts

I want to set a static attribute to my log file path so it is accessible to all my functions.  Is there a better way to do it?

 

Thanks!

<?php 
require_once(LIB_PATH."/".'initialize.php'); 



class logger {

private static $file;


	 function __construct() {
		logger::$file =  SITE_ROOT . "/logs/log.txt";
	}

	static function log_action($action="", $message = "") {
		global $session;



		$handle = fopen( logger::$file, 'at');
		fwrite($handle, date("Y-m-d H:i:s"). "| ". $action . " " . $message. "\n");
		fclose($handle);	
	} // End of log_action() function

	static function log_exists() {

		if (!file_exists(logger::$file)) {


		}

	} // End of log_exists() function

	static function read_log() {

	}  // End of read_log() function



} // end of logger class

$logger = new logger();


?>

 

I've answered this in your other thread but you don't need to make it static, especially if you're then defining it in the class constructor.  Just have it as private $file; and then refer to it in the class as $this->file.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.