Page 1 of 1

Fatal error: Using $this when not in object context

Posted: Thu Sep 13, 2007 3:48 am
by grace01
Hello,

When I run my php code follow:

Code: Select all

function log_event($event_type,$event) {
		
		$this->config = new inifile($_SERVER["DOCUMENT_ROOT"]."/config/default_config.ini");
		$this->log_path = $this->config->read_var("MAIN","log_path");
		
		if (!is_dir($this->log_path.date("Y"))) {
			mkdir($this->log_path.date("Y"));
		}
		if (!is_dir($this->log_path.date("Y")."/".date("m"))) {
			mkdir($this->log_path.date("Y")."/".date("m"));
		}
		$filename = $this->log_path.date("Y")."/".date("m")."/".date("d")."_applog.txt";
		$somecontent = "[DEV::".$event_type."]|[".date("Y-m-d H:i:s")."]|[".$_SESSION['user_session']->user_id."]|[".$_SERVER['REQUEST_METHOD']."]|[".$_SERVER['REQUEST_URI']."]|[".$event."]\n";

   		if (!$handle = fopen($filename, 'a')) {
       	//	print "Cannot open file ($filename)";
       		exit;
   		}
I got error:

Code: Select all

Fatal error: Using $this when not in object context in the first line of the function.
Thanks.

Posted: Thu Sep 13, 2007 6:37 am
by jeffery
Does the log_event function exist within a Class and is the class instantiated ?

Posted: Thu Sep 13, 2007 11:35 am
by John Cartwright
How are you calling log_event() ?