php - Referencing classes as className::methodName() -


as far thought either instantiate class so:

$class = new classname(); 

then use method in do:

$class->mymethod(); 

or if wanted use within class without instantiating do:

classname::mymethod(); 

i'm sure have used latter before without problems, why getting error says:

fatal error: using $this when not in object context 

my code using call is:

// display lists error message managelists::displaylists($e->getmessage()); 

the class follows..

class managelists {      /* constructor */      function __construct() {         $this->db_connection = connect_to_db('main');     }      function displaylists($etext = false, $success = false) {          // list data database         $lists = $this->getlists();          ......      }      function getlists() {          .........      }  } 

i getting error line..

$lists = $this->getlists(); 

when use format classname::methodname(), calling method 'statically', means you're calling method directly on class definition , not on instance of class. since can't call static methods instance, , $this represents instance of class, fatal error.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -