takuhii Posted November 9, 2006 Share Posted November 9, 2006 I have the following statement in my PHP document (running on a PHP 5 server):[code]<?phpfunction DoEvents($this) { global $_CONF, $_PAGE, $_TSM , $base; $jpp = $this->vars->data["jpp"]; <-------------------- this is the line at fault $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"] . "&" : "" )); }?>[/code]and when I execute the script I get the message: Fatal error: Using $this when not in object context in C:\Program Files\xampp\htdocs\jobs\pb_events.php on line 5pb_event.php is where my script lives. Can ANYONE tell me how to fix this, as I have NO IDEA :( Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/ Share on other sites More sharing options...
trq Posted November 9, 2006 Share Posted November 9, 2006 Is this function part of a class? Have you passed a valid object to the function? Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/#findComment-122165 Share on other sites More sharing options...
takuhii Posted November 9, 2006 Author Share Posted November 9, 2006 The function just sits in a file called pb_events.php. But the PHP file that calls this file, uses the following function:[code]function Run() { global $_TSM; if (file_exists("pb_events.php")) { include("pb_events.php"); $_TSM["PB_EVENTS"] = DoEvents(&$this); } if (is_object($this->templates["layout"])) { echo $this->templates["layout"]->Replace($_TSM); } }[/code] Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/#findComment-122172 Share on other sites More sharing options...
Zane Posted November 9, 2006 Share Posted November 9, 2006 http://us2.php.net/manual/en/reserved.phpNote if your running PHP5, $this is a reserved wordso you can't use it as parameter like this Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/#findComment-122241 Share on other sites More sharing options...
takuhii Posted November 10, 2006 Author Share Posted November 10, 2006 Could somebody explain to me how I could correct this? Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/#findComment-122577 Share on other sites More sharing options...
trq Posted November 10, 2006 Share Posted November 10, 2006 Change $this to $that. Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/#findComment-122599 Share on other sites More sharing options...
JasonLewis Posted November 10, 2006 Share Posted November 10, 2006 lol. yeh. pretty much use anything other then $this for a parameter. Link to comment https://forums.phpfreaks.com/topic/26704-using-this-when-not-in-object-help/#findComment-122604 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.