Jump to content

[PHP] Intialized class and not-initialized class, differences?I

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
Jacki

Jacki

    Learning Programmer

  • Members
  • PipPipPip
  • 80 posts
hi people,
I have a simple question. I have two ways to use a class in php:
//initializing object

$myclass = new myClass;

// or not initializing class..


$myclass->myfunction();

myClass::myfunction();

What are the differences? When I have to use one and when i have to use the other? Thanks... bye!
Posted Image

Posted Image

#2
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
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