Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 25th, 2006, 5:08 PM   #1
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 206
Rep Power: 4 BlazingWolf is on a distinguished road
$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
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old May 27th, 2006, 11:26 PM   #2
demon101
Hobbyist Programmer
 
demon101's Avatar
 
Join Date: Mar 2006
Location: westboro, ohio
Posts: 159
Rep Power: 0 demon101 is an unknown quantity at this point
Send a message via Yahoo to demon101
[PHP] $sql = "SELECT u_id FROM ".$this->settings['users_table']."WHERE ";[/PHP]

shouldnt that code be like that.
__________________
Demon101 Production's

Code Forums
demon101 is offline   Reply With Quote
Old May 28th, 2006, 1:59 AM   #3
coldDeath
Expert Programmer
 
coldDeath's Avatar
 
Join Date: Aug 2005
Location: UK
Posts: 862
Rep Power: 3 coldDeath is on a distinguished road
Send a message via AIM to coldDeath Send a message via Yahoo to coldDeath
I don't think so, as he is connecting it to the string below that line with the "." operator.
__________________
Join us at #programmingforums @ irc.freenode.net!

My software never has bugs. It just develops random features.
coldDeath is offline   Reply With Quote
Old May 28th, 2006, 1:51 PM   #4
BlazingWolf
Hobbyist Programmer
 
Join Date: Sep 2004
Posts: 206
Rep Power: 4 BlazingWolf is on a distinguished road
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.
__________________
_______________________________
BlazingWolf
BlazingWolf is offline   Reply With Quote
Old May 28th, 2006, 2:27 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Static methods don't have instances; that's why they're made static - share and share alike.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:47 AM.

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