Jump to content

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


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.