Fatal error: Using $this when not in object context

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
grace01
Forum Newbie
Posts: 5
Joined: Wed Sep 05, 2007 3:43 am

Fatal error: Using $this when not in object context

Post 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.
jeffery
Forum Contributor
Posts: 105
Joined: Mon Apr 03, 2006 3:13 am
Location: Melbourne, Australia
Contact:

Post by jeffery »

Does the log_event function exist within a Class and is the class instantiated ?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

How are you calling log_event() ?
Post Reply