PHP Classes :: & ->

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
What is the difference between "::" and "->" when using classes?

It always hard to find documentation for something that i only a
symbol. :)

Re: PHP Classes :: & ->

mjs7231 wrote:

Quoted text here. Click to load it

:: calls a class method statically - that is, you don't have to have an
instance of the class.

-> calls a class method as part of an object.

If you have something like:

require 'MyClass.php';
$x = new MyClass();

Then you'd use $x->method() to call the methods in the class as part of
the instance/object.

You can also do something like:

require 'MyClass.php';
$res = MyClass::isError($obj);

In most cases, static methods need a parameter, unless they are simply
output routines.


Justin Koivisto, ZCE -

Re: PHP Classes :: & ->

great explination, thanks. :)

Site Timeline