+ Reply to Thread
Results 1 to 2 of 2

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

  1. #1
    Learning Programmer Jacki is on a distinguished road Jacki's Avatar
    Join Date
    Sep 2009
    Location
    Switzerland
    Age
    16
    Posts
    80

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

    hi people,
    I have a simple question. I have two ways to use a class in php:
    Code:
    //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!



  2. #2
    Moderator Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan is a glorious beacon of light Orjan's Avatar
    Join Date
    Sep 2007
    Location
    Karlstad, Sweden
    Age
    34
    Posts
    2,613
    Blog Entries
    7

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

    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.
    __________________________________________
    Ask me: Orjan | Contribute to the Wiki! | Make your own Programming blog!
    I usually play eRepublik and Travian when I'm not on CodeCall

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts