DragoNight
New Member
Up until the yesterday I though that both of these methods for accessing a class where identical. Google turned up noting (either that or my keywords were bad). What is the difference between accessing a class by defining a new instance of the class rather than just calling the class methods directly. I hardly understood what I just ask, since I have not a clue what I'm asking but allow me to give a few examples to help out.For as long as I have been using classes in PHP I have been defining a instance of the class then accessing the methods from that variable. Here is an example:\[code\]<?phpclass Myclass{ public function my_method() { return "This is my method"; }}$myclass = new Myclass();echo $myclass->my_method(); // output: This is my method?>\[/code\]What is the difference between that and doing this?\[code\]<?phpclass Myclass{ public function my_method() { return "This is my method"; }}echo Myclass::my_method(); // output: This is my method?>\[/code\]I hope I was clear enough. If not a brief synopsis would be - What is the difference between creating a new instance of a class then calling a method of the class with "$class->mymethod();," or just directly calling the method like so: "Myclass::mymethod();"?Thanks in advanced.