hi people,
I have a simple question. I have two ways to use a class in php:
What are the differences? When I have to use one and when i have to use the other? Thanks... bye!Code://initializing object
$myclass = new myClass;
// or not initializing class..
$myclass->myfunction();
myClass::myfunction();
if you instansiate an object from the class, as you do in your first example, it will be initialized as well, having it's constructor done, creating an object of it's members and methods. with this object, you can perform different things as in your second codeline.
second line of yours will only work on instansiated objects, and that normally performs an action on that object, or retirns info from the object.
third line is what most call a static call to a method, usually a method that does not rely on anything else in the class, that just performs a calculation or what it is meant to do.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks