My hosting provider just upgraded from PHP4 to PHP5. My login page has now stopped working :queasy:
It gives me the error
Fatal error: Cannot re-assign $this in file.... on line 22
I've commented line 22 in the code so you can see which one it 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];
}
}
I've looked on the net loads to try to find an answer. I understand there might be a problem with the use of the word this, but I'm really not sure what to do to fix it. My programmer is unavailiable and I can't wait a week to get it sorted. Any help that can be given would be very much appreciated.
Thanks,
Mike A stop gap measure would be to change:
$this = false;
to:
throw new Exception('Database query error');A stop gap measure would be to change:
$this = false;
to:
throw new Exception('Database query error');
Thank you so much. I've spent about 8 hours looking everywhere I possibly can for an answer. This seems to have worked. I can now log in even if the graphs don't work.
Is there a reason it can't be a permenant solution rather than just a stop gap?
I really do appreciate you spending the time to answer. Thanks,
MikeIs there a reason it can't be a permenant solution rather than just a stop gap?
Well, suppose the query failed for some reason* (e.g., could not connect to the database server, could not select the database, query incorrect), an exception would be thrown. At the moment your code presumably would not handle the exception, so the script would just die rather ungracefully.
You could turn it into a more permanent solutipn by handling the exception gracefully (e.g., instead of terminating the script immediately, print a friendly error message, then continue loading the rest of the page that is still relevant). There are other possibilities, e.g., the database wrapper that you are using could throw an exception instead (assuming that it is a custom made wrapper class (or library of classes)).
* Note that returning zero rows in the result set is not a failure. If the user id supplied does not exist in the users table, you might have an array out of bounds error when assigning $res[0] to $this->name and $res[1] to $this->email.
It gives me the error
Fatal error: Cannot re-assign $this in file.... on line 22
I've commented line 22 in the code so you can see which one it 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];
}
}
I've looked on the net loads to try to find an answer. I understand there might be a problem with the use of the word this, but I'm really not sure what to do to fix it. My programmer is unavailiable and I can't wait a week to get it sorted. Any help that can be given would be very much appreciated.
Thanks,
Mike A stop gap measure would be to change:
$this = false;
to:
throw new Exception('Database query error');A stop gap measure would be to change:
$this = false;
to:
throw new Exception('Database query error');
Thank you so much. I've spent about 8 hours looking everywhere I possibly can for an answer. This seems to have worked. I can now log in even if the graphs don't work.
Is there a reason it can't be a permenant solution rather than just a stop gap?
I really do appreciate you spending the time to answer. Thanks,
MikeIs there a reason it can't be a permenant solution rather than just a stop gap?
Well, suppose the query failed for some reason* (e.g., could not connect to the database server, could not select the database, query incorrect), an exception would be thrown. At the moment your code presumably would not handle the exception, so the script would just die rather ungracefully.
You could turn it into a more permanent solutipn by handling the exception gracefully (e.g., instead of terminating the script immediately, print a friendly error message, then continue loading the rest of the page that is still relevant). There are other possibilities, e.g., the database wrapper that you are using could throw an exception instead (assuming that it is a custom made wrapper class (or library of classes)).
* Note that returning zero rows in the result set is not a failure. If the user id supplied does not exist in the users table, you might have an array out of bounds error when assigning $res[0] to $this->name and $res[1] to $this->email.