Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>-&gt;</code> is used when referring to a member of an object.</p> <p><code>::</code> is the <a href="http://www.php.net/manual/en/language.oop5.paamayim-nekudotayim.php" rel="noreferrer">Scope Resolution Operator</a> and is used to refer to a static member of a Class.</p> <p>Consider the following class:</p> <pre><code>class FooBar { public static function fizz() { echo "Fizz"; } public function buzz() { echo "Buzz"; } } </code></pre> <p>You would call the function <code>buzz()</code> using <code>-&gt;</code>:</p> <pre><code>$myFooBar = new FooBar(); $myFooBar-&gt;buzz(); </code></pre> <p>But would use <code>::</code> to call the functon <code>fizz()</code>, as it is a static member (a member which doesn't require an instance of the class to be called):</p> <pre><code>FooBar::fizz(); </code></pre> <hr> <p>Also, while we are talking about the difference between <strong>static</strong> members versus <strong>instantiated</strong> members, you cannot use <code>$this</code> to refer to the current instance within <strong>static</strong> members. You use <a href="http://www.php.net/manual/en/language.oop5.static.php" rel="noreferrer"><code>self</code></a> instead (no leading <code>$</code>) which refers to the current class, or <a href="http://www.php.net/manual/en/language.oop5.static.php" rel="noreferrer"><code>parent</code></a> if you want to refer to the parent class, or if you have the pleasure of working with PHP 5.3.0, <a href="http://www.php.net/manual/en/language.oop5.late-static-bindings.php" rel="noreferrer"><code>static</code></a> (which allows for late static binding).</p> <hr> <p>The documentation uses <code>::</code> to refer to a function inside a class as the class name in the header is not an instance of the class. Still using the same example, a documentation entry referring to the function <code>buzz()</code> would use the following header:</p> <pre><code>FooBar::buzz </code></pre> <p>But unless the documentation specifies it's a static member, you will need to use <code>-&gt;</code> on an instance to call it:</p> <pre><code>$myFooBar = new FooBar(); $myFooBar-&gt;buzz(); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload