sfc Posted July 2, 2010 Share Posted July 2, 2010 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/206562-automatically-setting-static-attributes-is-this-the-only-way-to-do-it/ Share on other sites More sharing options...
sfc Posted July 3, 2010 Author Share Posted July 3, 2010 Is it safe to assume that this is the best/only way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/206562-automatically-setting-static-attributes-is-this-the-only-way-to-do-it/#findComment-1080654 Share on other sites More sharing options...
Cagecrawler Posted July 3, 2010 Share Posted July 3, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/206562-automatically-setting-static-attributes-is-this-the-only-way-to-do-it/#findComment-1080655 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.