August 30th, 2013, 05:58 AM
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
August 30th, 2013, 06:14 AM
post your code on what you need explanation on?
i think that
$obj = new Object();
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.
August 30th, 2013, 06:18 AM
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
August 30th, 2013, 06:22 AM
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!