#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    12
    Rep Power
    0

    Calling inside and outside object


    i got a doubt in php that,,,while going thorough a couple of codes i found this,,,calling a method inside object and calling a method outside of object..i have no idea what this means,,,,can any one please clarify me my doubt??

    thanks in advance ,,Sam
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,990
    Rep Power
    375
    post your code on what you need explanation on?

    i think that

    $obj = new Object();
    $obj->some_method();

    is how you call a method inside an object. On the other hand:

    $obj = Object::some_method();

    is how you call a method from "outside" an object.

    The difference is that in the 2nd example, the method is static. meaning you dont have to create an object to use it.

    Generally it doesnt make a difference.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    12
    Rep Power
    0

    one more doubt


    one more doubt....
    why we need to do it..i mean call from inside and outside of object.
    can u tell me please?
    thanks in advance,,Sam
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Dec 2004
    Posts
    2,990
    Rep Power
    375
    depends.. sometimes functions need objects, sometimes they dont.. e.g. if you had a validation class you might do

    $message = $Class::validate_email($email) // you dont need to create an object!

IMN logo majestic logo threadwatch logo seochat tools logo