hi can you help me l trying to run a certain php job recruitment system but l am getting the following error:

Fatal error: Using $this when not in object context in D:\xampp\htdocs\jobs\pb_events.php on line 5

and below is the referred pb_events.php script.

<?php
function DoEvents($this) {
	global $_CONF, $_PAGE, $_TSM , $base;

	$jpp = $this->vars->data["jpp"];

	$cache["departments"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_departments]}");
	$cache["locations"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_location]}");
	$cache["names"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_names]}");
	$cache["categories"] = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_categories]}");

	//add the categories and the departments to the template
	if (is_array($cache["categories"])) {
		$_TSM["CATEGORIES"] = $base->html->Table($this->templates["categories"], "Categories" , $cache["categories"]);
	} else
		$_TSM["CATEGORIES"] = "";

	if (is_array($cache["departments"])) {
		$_TSM["DEPARTMENTS"] = $base->html->Table($this->templates["departments"], "Departments" , $cache["departments"]);
	} else
		$_TSM["DEPARTMENTS"] = "";
	

	$_pb_used_vars = array("1" => "departments" , "locations" , "names" , "categories");
	$_pb_used_keys = array("1" => "department" , "location" , "name" , "category");

	//preprocess for assinging the correct id
	foreach ($_pb_used_vars as $k => $v) {
		if (is_array($cache[$v])) {
			foreach ($cache[$v] as $key => $val) {
				$cache["_" . $v][$val[$_pb_used_keys[$k] . "_id" ]] = $val[$_pb_used_keys[$k] . "_title" ];
			}
			
			$cache[$v] = $cache["_" . $v];
			unset($cache["_" . $v]);
		}
	}

	$_GET["page"] = $_GET["page"] > 0 ? $_GET["page"] : 1;

	$time = time();

	switch ($_GET["sub"]) {
		case "details":
			$job = $this->db->QFetchArray("SELECT * FROM {$this->tables[job_list]} WHERE job_id = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");

			//check if is a valid job
			if (is_array($job)) {

				//add the extra data
				$job["job_category_title"] = $cache["categories"][$job["job_category"]];
				$job["job_department_title"] = $cache["departments"][$job["job_department"]];
				$job["job_location_title"] = $cache["locations"][$job["job_location"]];
				$job["job_name_title"] = $cache["names"][$job["job_title"]];

				$job["referer"] = $_SERVER["HTTP_REFERER"] ? $_SERVER["HTTP_REFERER"] : "list.php";
				$job["job_salary"] = number_format($job["job_salary"] , 2 );
				$job["details_link"] = $job["job_link"] ? $this->templates["details"]->blocks["Link"]->Replace($job) : "";

				return $this->templates["details"]->blocks["Main"]->Replace($job);

			} else {
				//redirect to error.php
				header("Location: error.php");
				exit;
			}			
		break;

		case "department":

			//check if is a valid department
			if ($cache["departments"][$_GET["id"]]) {

				$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE `job_department` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}' LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
				$count = $this->db->RowCount($this->tables["job_list"] , "WHERE `job_department` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");

			} else {
				//redirect to error.php
				header("Location: error.php");
				exit;
			}
			
		break;

		case "category":

			//check if is a valid department
			if ($cache["categories"][$_GET["id"]]) {

				$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE `job_category` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
				$count = $this->db->RowCount($this->tables["job_list"] , "WHERE `job_category` = '{$_GET[id]}' AND job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");

			} else {
				//redirect to error.php
				header("Location: error.php");
				exit;
			}
			
		break;

		case "error":
			return $this->templates["error"]->output;
		break;

		case "search":
			if ($_GET["what"]) {
				//searching in cache
				if (is_array($cache["names"])) {
					foreach ($cache["names"] as $key => $val) {
						if (stristr($val , $_GET["what"])) {
							$found[] = $key;
						}						
					}
					
				}
								
				//ok search for the list of jobs
				$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE (job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}') AND (`job_description` LIKE '%{$_GET[what]}%' or `job_summary` LIKE '%{$_GET[what]}%' " . (is_array($found) ? " OR `job_title` in (" . implode("," , $found) . ")" : "" ) . " ) LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
				$count = $this->db->RowCount($this->tables["job_list"] , "WHERE (job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}') AND  (`job_description` LIKE '%{$_GET[what]}%' or `job_summary` LIKE '%{$_GET[what]}%' " . (is_array($found) ? " OR `job_title` in (" . implode("," , $found) . ")" : "") . ")");

				break;
			}
		
		default:
			$jobs = $this->db->QFetchRowArray("SELECT * FROM {$this->tables[job_list]} WHERE job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}' LIMIT " . ($_GET['page'] -1 )* $jpp . " , {$jpp}");
			$count = $this->db->RowCount($this->tables["job_list"] , "WHERE job_status=0 AND job_date_start <= '{$time}' and job_date_end >= '{$time}'");
		break;		
	}
	
	$alternance = 1;

	if (is_array($jobs)) {
		foreach ($jobs as $key => $val) {
			//add the extra data
			$jobs[$key]["job_category_title"] = $cache["categories"][$val["job_category"]];
			$jobs[$key]["job_department_title"] = $cache["departments"][$val["job_department"]];
			$jobs[$key]["job_location_title"] = $cache["locations"][$val["job_location"]];
			$jobs[$key]["job_name_title"] = $cache["names"][$val["job_title"]];

			//also add the alternance template
			$jobs[$key]["alternance"] = $this->templates["list"]->blocks["Alternance" . $alternance]->output;

			//switch
			$alternance = !$alternance;
		}		
	}

	//build a table with the results;

	//well ok, now show the list with the templates

	return $base->html->Table($this->templates["list"],"List",$jobs,true,$count,$jpp,$_GET["page"],$this->templates["paging"],array(
																																		"base" => in_array($_GET["sub"] , array ("department" , "category" , "search")) ? $_GET["sub"] . ".php" : "list.php" ,
																																		"extra" => $_GET["id"] ? "id=" . $_GET["id"] . "&" : "",
																																		"what" => $_GET["what"] ? "what=" . $_GET["what"] . "&" : ""

																																	));
 
}
?>

The $this variable you're using in your code is just a variable. ie

function DoEvents($this){
   echo $this;
}
DoEvents('string'); //will echo string

Unless your function is inside a class, $this would refer to the current class. ex:

//http://www.php.net/manual/en/language.oop5.basic.php
class SimpleClass
{
    // property declaration
    public $var = 'a default value';

    // method declaration
    public function displayVar() {
        echo $this->var;
    }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.