Jump to content

Upgrade to PHP5 Errors


Emase

Recommended Posts

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

 

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:

 

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

Link to comment
https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/
Share on other sites

The second fatal error is from line 8 of the follow code. (Shown with <<<< arrows).

 

<?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:

 

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];
	}
}

 

 

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

 

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.

 

:'(

 

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:

 

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.

 

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

Can we see what the code looked like before you made any changes?

 

Sorry,

 

The function it doesn't like is:

 

	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];
	}
}

 

Fatal error: Cannot re-assign $this on line 22
- Marked in code

 

Thanks for your help,

 

Mike

Because your are setting $this to false if the query fails it is breaking your code, change it to:

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];
    }
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.