PHP Classes :: & ->

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mjs7231

    #1

    PHP Classes :: & ->

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

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

  • Justin Koivisto

    #2
    Re: PHP Classes :: & ->

    mjs7231 wrote:
    [color=blue]
    > What is the difference between "::" and "->" when using classes?
    >
    > It always hard to find documentation for something that i only a
    > symbol. :)[/color]

    :: 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::isErro r($obj);

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

    HTH

    --
    Justin Koivisto, ZCE - justin@koivi.co m

    Comment

    • mjs7231

      #3
      Re: PHP Classes :: & ->

      great explination, thanks. :)

      Comment

      Working...