Author Topic: Upgrade to PHP5 Errors  (Read 885 times)

0 Members and 1 Guest are viewing this topic.

Offline EmaseTopic starter

  • Irregular
  • Posts: 5
    • View Profile
Upgrade to PHP5 Errors
« on: March 09, 2008, 07:30:18 AM »
My hosting provider upgraded to php5 a few days ago, causing me some major problems. When pointing my browser to my normal login page, I got the error

Code: [Select]
Fatal error: Cannot re-assign $this in filename....
I went through all my code renaming all $this to $this_var.

The login screen showed and I though I'd fixed the problem. However, when I try to login I now get:

Code: [Select]
Fatal error: Call to undefined method stdClass::User() in filename...

Everything worked fine until it was upgraded to php5.  ??? I'm a complete novice with php and I'd really appreciate any help.

Thanks,

Mike

Offline EmaseTopic starter

  • Irregular
  • Posts: 5
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #1 on: March 09, 2008, 07:49:09 AM »
The second fatal error is from line 8 of the follow code. (Shown with <<<< arrows).

Code: [Select]
<?php
class Admin extends User
{
function Admin ($id)
{
global $db;
$this_var->type "admin";
$this_var->User($id); // <<<< This Line
$this_var->object_ids $db->GetCol("SELECT id FROM campaigns ORDER BY name");
}

function RequireAdmin ()
{
return true;
}
}
?>

I think this problem might be the same as http://www.phpfreaks.com/forums/index.php/topic,109235.0.html, but I don't really understand the solution.

The original error was with the function below:

Code: [Select]
function User ($id)
{
global $db;
$this->id = intval($id);
$this->objects = array();
$res = $db->GetRow("SELECT username, email FROM users WHERE id=".$this->id);
if (empty($res)){
$this_var = false;
} else {
$this->name = $res[0];
$this->email = $res[1];
}
}

« Last Edit: March 09, 2008, 07:58:09 AM by Emase »

Offline Thomisback

  • Enthusiast
  • Posts: 138
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #2 on: March 09, 2008, 08:26:05 AM »
Maybe you should try:

http://www.dirfile.com/php4_to_php5_converter.htm

That's all I can do, i'm still a beginner  :-\

Offline EmaseTopic starter

  • Irregular
  • Posts: 5
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #3 on: March 09, 2008, 08:42:12 AM »
Maybe you should try:

http://www.dirfile.com/php4_to_php5_converter.htm

That's all I can do, i'm still a beginner  :-\

On the homepage it says

Quote
php4 to php5 Converter - Discontinued
Important Note: php4 to php5 Converter has been discontinued due to some technical errors. We will release this software as soon as the errors are solved.

 :'(

Offline Thomisback

  • Enthusiast
  • Posts: 138
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #4 on: March 09, 2008, 08:45:59 AM »

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #5 on: March 09, 2008, 08:48:26 AM »
Quote
I went through all my code renaming all $this to $this_var

Which likely broke allot of functionality.

Seems to me you need to find a programmer.

Offline EmaseTopic starter

  • Irregular
  • Posts: 5
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #6 on: March 09, 2008, 09:09:31 AM »
Quote
I went through all my code renaming all $this to $this_var

Which likely broke allot of functionality.

Seems to me you need to find a programmer.

I'd read that this should solve the problem. I've now rolled back to exactly how it was before and am getting the following error again:

Quote
Fatal error: Cannot re-assign $this


The problem is that my programmer is currently not availiable hence why I am trying to solve the problem.

I can't get a proper download of that file. I've tried the first 20 or so on Google which all seem to be the same. When downloading though, the file is 100k instead of 3 meg. This is the same on all of the sites.

Code: [Select]
function User ($id)
{
global $db;
$this->id = intval($id);
$this->objects = array();
$res = $db->GetRow("SELECT username, email FROM users WHERE id=".$this->id);
if (empty($res)){
$this_var = false;   // The line it doesn't like.
} else {
$this->name = $res[0];
$this->email = $res[1];
}
}

Thanks for the help,
Mike
« Last Edit: March 09, 2008, 09:13:57 AM by Emase »

Offline thorpe

  • Administrator
  • 'Mind Boggling!'
  • *
  • Posts: 29,255
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #7 on: March 09, 2008, 09:18:27 AM »
Can we see what the code looked like before you made any changes?

Offline EmaseTopic starter

  • Irregular
  • Posts: 5
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #8 on: March 09, 2008, 09:21:19 AM »
Can we see what the code looked like before you made any changes?

Sorry,

The function it doesn't like is:

Code: [Select]
function User ($id)
{
global $db;
$this->id = intval($id);
$this->objects = array();
$res = $db->GetRow("SELECT username, email FROM users WHERE id=".$this->id);
if (empty($res)){
$this = false;   //Line 22
} else {
$this->name = $res[0];
$this->email = $res[1];
}
}
   
Quote
Fatal error: Cannot re-assign $this on line 22
- Marked in code

Thanks for your help,

Mike

Offline wildteen88

  • Guru
  • 'Insane!'
  • *
  • Posts: 12,021
  • Gender: Male
    • View Profile
Re: Upgrade to PHP5 Errors
« Reply #9 on: March 09, 2008, 10:53:19 AM »
Because your are setting $this to false if the query fails it is breaking your code, change it to:
Code: [Select]
function User ($id)
{
    global $db;

    $this->id = intval($id);
    $this->objects = array();

    $res = $db->GetRow("SELECT username, email FROM users WHERE id=".$this->id);

    if($res)
    {
        $this->name = $res[0];
        $this->email = $res[1];
    }
}