   [web] quick question on PHP error
  Sorry if this sounds like a really really dumb question, but I just can't figure out what I'm doing wrong here. I have a class called drs_rating and it's stored in a file called rate_fns.php. The class contains a function like this:function convert_rating($rating) { for($i=0; $i<$rating; $i++){ $rat_img .= "<img src='star.jpg' border='0'>"; }return $rat_img; }And in my drs_template file I have this code:$stars = $drsR->convert_rating($puser_auth_lvl);and I get this error:Fatal error: Call to a member function convert_rating() on a non-object in C:\Program Files\xampp\htdocs\suite\FS\core\drs_template.php on line 90Does anyone know why? Thanks in advance for reading. :)   
  How did you initialize $drsR?   ;  What exactly is the use of that class? Do you just use it via static methods? You could do it like this:<?phpclass MyClass{  static public function foo($name)  {    return "Hello, $name!";  }}print MyClass::foo('World');?>There is no class variable needed. Back to your error... Make sure you are doing this:$drsR = new drs_rating;   ;  Sorry, I should have been more clear.I'm init the class like this: $drsR= new drs_rating();The function is defined like this class drs_rating {  function drs_rating() { }  function getRatingByID($user_id) {  $q = mysql_query( "SELECT rating FROM users WHERE usersID = '$user_id';" ); if(!$q) { return(0); } else { return(1); } return(0); }  function convert_rating($rating) { for($i=0; $i<$rating; $i++){ $rat_img .= "<img src='star.jpg' border='0'>"; }return $rat_img; } };  Check these two things:1) Make sure that you call $drsR = new $drs_rating(); before you call $stars = $drsR->convert_rating($puser_auth_lvl);2) If your template code (where $stars = $drsR->convert_rating($puser_auth_lvl); is) is inside a function, then make sure that at the top it says: global $drsR; (see variable scope).   ;  haha, thanks. That indeed did work. I had that there (some sort of global) at one point in time but a friend told me that globals are bad, shouldn't be used, and will eventually be phased out. Does anyone know why he said this? Is there any truth in that? Thanks again for the help everyone. I can start programming again! :)   ;  Some languages don't have globals, but PHP always will. Relying heavily on globals in any language is bad. With PHP, I like to use static classes to hide globals. This helps out a lot if you want to re-use your code.For a simple comparison:<?phpclass HTTP{  static public function redirect($url)  {    header("Location: $url");    exit;  }}HTTP::redirect('/foo');// vsfunction http_redirect($url){    header("Location: $url");    exit;}http_redirect('/foo');?>With the Class method, I can store all sorts of variables (if need be) that only the class needs to know about. I don't have to worry about overriding other variables from who knows where. I can easily group related things into the same class. Also, with PHP5 you can set up an __autoload function so that you don't even have to include your class files by hand. As with all things, it comes at a slight performance penalty - but you're doing pretty good if that ends up being your bottleneck.   ;Quote:Original post by sathenzarhaha, thanks. That indeed did work. I had that there (some sort of global) at one point in time but a friend told me that globals are bad, shouldn't be used, and will eventually be phased out. Does anyone know why he said this? Is there any truth in that? Thanks again for the help everyone. I can start programming again! :)He was talking about global variables, not about using the global keyword inside a function. Global variables can be bad if you overuse them because it can lead to suble errors. E.g. accidentally naming a local variable as a global one, one part of a script accidentally another part, etcetera. It's not that all gloabls are bad, but overusing them is bad because it makes things overly complex.