Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>DO NOT USE <code>self::</code>, use <code>static::</code></strong></p> <p>There is another aspect of self:: that is worth mentioning. Annoyingly <strong><code>self::</code> refers to the scope at the point of definition not at the point of execution</strong>. Consider this simple class with two methods:</p> <pre><code>class Person { public static function status() { self::getStatus(); } protected static function getStatus() { echo "Person is alive"; } } </code></pre> <p>If we call <code>Person::status()</code> we will see "Person is alive" . Now consider what happens when we make a class that inherits from this:</p> <pre><code>class Deceased extends Person { protected static function getStatus() { echo "Person is deceased"; } } </code></pre> <p>Calling <code>Deceased::status()</code> we would expect to see "Person is deceased" however what we see is "Person is alive" as the scope contains the original method definition when call to <code>self::getStatus()</code> was defined.</p> <p>PHP 5.3 has a solution. the <strong><code>static::</code></strong> resolution operator implements "late static binding" which is a fancy way of saying that it's bound to the scope of the class called. Change the line in <code>status()</code> to <code>static::getStatus()</code> and the results are what you would expect. In older versions of PHP you will have to find a kludge to do this.</p> <p>See <a href="http://php.net/manual/en/language.oop5.late-static-bindings.php" rel="nofollow noreferrer">PHP Documentation</a></p> <p>So to answer the question not as asked ...</p> <p><code>$this-&gt;</code> refers to the current object (an instance of a class), whereas <code>static::</code> refers to a class</p>
    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. 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