![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
$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 |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
|
[PHP] $sql = "SELECT u_id FROM ".$this->settings['users_table']."WHERE ";[/PHP]
shouldnt that code be like that. |
|
|
|
|
|
#3 |
|
Expert Programmer
|
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.
|
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Sep 2004
Posts: 207
Rep Power: 5
![]() |
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 |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|