Emase Posted March 9, 2008 Share Posted March 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/ Share on other sites More sharing options...
Emase Posted March 9, 2008 Author Share Posted March 9, 2008 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]; } } Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487646 Share on other sites More sharing options...
Thomisback Posted March 9, 2008 Share Posted March 9, 2008 Maybe you should try: http://www.dirfile.com/php4_to_php5_converter.htm That's all I can do, i'm still a beginner :-\ Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487662 Share on other sites More sharing options...
Emase Posted March 9, 2008 Author Share Posted March 9, 2008 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. :'( Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487672 Share on other sites More sharing options...
Thomisback Posted March 9, 2008 Share Posted March 9, 2008 I think there are loads more: http://www.google.com/search?hl=en&q=php4+to+php5+converter&btnG=Google+Search Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487677 Share on other sites More sharing options...
trq Posted March 9, 2008 Share Posted March 9, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487679 Share on other sites More sharing options...
Emase Posted March 9, 2008 Author Share Posted March 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487692 Share on other sites More sharing options...
trq Posted March 9, 2008 Share Posted March 9, 2008 Can we see what the code looked like before you made any changes? Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487697 Share on other sites More sharing options...
Emase Posted March 9, 2008 Author Share Posted March 9, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487698 Share on other sites More sharing options...
wildteen88 Posted March 9, 2008 Share Posted March 9, 2008 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]; } } Quote Link to comment https://forums.phpfreaks.com/topic/95202-upgrade-to-php5-errors/#findComment-487761 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.