Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Fatal error: Using $this when not in object context in .../pb_events.php on line 29
Old 02-09-2009, 09:23 PM Fatal error: Using $this when not in object context in .../pb_events.php on line 29
Junior Talker

Posts: 1
Trades: 0
Hi everybody,

I hope somebody can help me out with this.

I have the followed script (pb_events.php):

PHP Code:
<?php
//define ("PB_CRYPT_LINKS" , "1");
function DoEvents($this) {
 global 
$_CONF $_TSM;
 
$_TSM["MENU"] = "";
 
//checking if user is logged in
 
if (!$_SESSION["minibase"]["user"]) {
  if (
$_SERVER["REQUEST_METHOD"] == "POST") {
   
//autentificate
   
$user $this->db->QFetchArray("select * from {$this->tables[users]} where `user_login` = '{$_POST[user]}' AND `user_password` = '{$_POST[pass]}'");
   if (
is_array($user)) {
    
$_SESSION["minibase"]["user"] = 1;
    
$_SESSION["minibase"]["raw"] = $user;
    
//redirecing to viuw sites
    
header("Location: $_CONF[default_location]");
    exit;
   } else
    return 
$this->templates["login"]->blocks["Login"]->output;
  } else
   return 
$this->templates["login"]->blocks["Login"]->output;
 }
 if (
$_SESSION["minibase"]["raw"]["user_level"] == 0) {
  
$_TSM["MENU"] = $this->templates["login"]->blocks["MenuAdmin"]->output;
 } else {
  
$_TSM["MENU"] = $this->templates["login"]->blocks["MenuUser"]->output;
 }
 if (!
$_POST["task_user"])
  
$_POST["task_user"] = $_SESSION["minibase"]["user"];
 if(
$_SESSION["minibase"]["raw"]["user_level"] == 1) {
  
$_CONF["forms"]["adminpath"] = $_CONF["forms"]["userpath"];
 }
 switch (
$_GET["sub"]) {
  case 
"logout":
   unset(
$_SESSION["minibase"]["user"]);
   
header("Location: index.php");
   return 
$this->templates["login"]->EmptyVars();
  break;
  case 
"properties":
  case 
"schools":
  case 
"areas"
  case 
"types":
  case 
"photos":
   if (
$_POST["price"]) {
    
$_POST["price"] = str_replace("," "" $_POST["price"]);    
   }
   if (
$_POST["selling_price"]) {
    
$_POST["selling_price"] = str_replace("," "" $_POST["selling_price"]);
   }
 
 
 
   if ((
$_GET["sub"] == "properties") && ($_GET["action"] == "details")) {
    
$task = new CSQLAdmin("photos"$_CONF["forms"]["admintemplate"],$this->db,$this->tables $extra);
    
$extra["details"]["after"] = $task->DoEvents();    
   }
 
 
   
$data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->tables $extra);
   return 
$data->DoEvents();
  break;
  case 
"users":
   if (!
$_POST["job_date"]) {
    
$_POST["job_date"] = time();
   }
   if (!
$_POST["job_user"]) {
    
$_POST["job_user"] = $_SESSION["minibase"]["raw"]["user_id"];
   }
   
$data = new CSQLAdmin($_GET["sub"], $_CONF["forms"]["admintemplate"],$this->db,$this->tables);
   return 
$data->DoEvents();
  break;
  case 
"settings":
   
$file $_GET["sub"] . ".xml";
   
$data = new CForm($_CONF["forms"]["admintemplate"],$this->db,$this->tables);
   if (
$_GET["action"] == "store") {
    if (
is_array($values $data->Validate($_CONF["forms"]["adminpath"] . $file,$_POST))) {
     return 
$data->Show($_CONF["forms"]["adminpath"] . $file$values);
    } else {
     
$this->vars->SetAll($_POST);
     
$this->vars->Save();
     
header("location: index.php?mod=eshop&sub=" $_GET["sub"]);
     exit;
    }
 
   }
 
   return 
$data->Show($_CONF["forms"]["adminpath"] . $file , array("values"=>$this->vars->data));
  break;
 }
}
?>
...and receive this error:
Code:
Fatal error: Using $this when not in object context in /home/rascals/public_html/test/admin/pb_events.php on line 29
I guess this has something to do with the compatibility of PHP 4 and 5 but I have no clue how I would have to alter this script to make it work!

Thx for any help!
Pascal
pascalwy is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-10-2009, 01:49 PM Re: Fatal error: Using $this when not in object context in .../pb_events.php on line
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Line 29 (I think is):
PHP Code:
$this->db->QFetchArray/*snip*/ 
The problem is you can only use $this in OOP (classes), your using it in a function (As a variable as anderswc has pointed out, change the name of it to something else).

Also, this will only work in PHP5 or above (when OOP was implemented)
Check with the source of the script for more help.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 02-12-2009 at 06:53 AM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-10-2009, 02:13 PM Re: Fatal error: Using $this when not in object context in .../pb_events.php on line
wayfarer07's Avatar
Poo on You

Latest Blog Post:
Introducing WowWindow
Posts: 3,985
Name: Abel Mohler
Location: Asheville, North Carolina USA
Trades: 0
Plus, the first line: function DoEvents($this) {

Are you sure this function isn't meant to be defined inside of a class? If that is the case, using $this will be ok.
__________________
Join me on
Please login or register to view this content. Registration is FREE
wayfarer07 is offline
Reply With Quote
View Public Profile Visit wayfarer07's homepage!
 
Old 02-11-2009, 04:53 PM Re: Fatal error: Using $this when not in object context in .../pb_events.php on line
anderswc's Avatar
Super Talker

Posts: 132
Name: Will Anderson
Location: Terre Haute, IN
Trades: 0
Actually, you probably just want to rename $this to some other variable name. That should solve your problems.
__________________
Will Anderson

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
anderswc is offline
Reply With Quote
View Public Profile Visit anderswc's homepage!
 
Reply     « Reply to Fatal error: Using $this when not in object context in .../pb_events.php on line 29
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23565 seconds with 12 queries