Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   PHP (http://www.programmingforums.org/forum29.html)
-   -   $this Out of Context (http://www.programmingforums.org/showthread.php?t=9987)

BlazingWolf May 25th, 2006 5:08 PM

$this Out of Context
 
Having a wierd problem with a class i'm trying to write

[PHP]
public static function getID($username)
{
$username = $this->db->escape($username);//this line erros
$sql = "SELECT u_id FROM ".$this->settings['users_table']."WHERE "
.$this->settings['username_col']."='".$username."'";
$res = $this->db->query($sql);
$res = $this->db->fetchArray($res);
$id = $res['u_id'];
return $id;
}
[/PHP]

The error message "Using $this when not in object context". Not really sure what I'm doing wrong, and I used the same line in other lines and it does not error.

Thanks

demon101 May 27th, 2006 11:26 PM

[PHP] $sql = "SELECT u_id FROM ".$this->settings['users_table']."WHERE ";[/PHP]

shouldnt that code be like that.

coldDeath May 28th, 2006 1:59 AM

I don't think so, as he is connecting it to the string below that line with the "." operator.

BlazingWolf May 28th, 2006 1:51 PM

The onlt thing that is wrong with that line is there needs to be a space between the " and the W in where.

The problem was because the method is static it has no instance, I wasn't aware things worked like that mabey it is a wrinkle in PHP's OOP model.

DaWei May 28th, 2006 2:27 PM

Static methods don't have instances; that's why they're made static - share and share alike.


All times are GMT -5. The time now is 4:35 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC