·  PHP – Syntax – Keywords – self

 

- Info:

  - self refers to the type of class.

  - self is for use in static member functions to allow you to access static member variables.

  - But you can also use it from inside non-static methods.

  - Because self is not an object, but it refers to the current class, you use it like: self::$member.

  - This info is based http://stackoverflow.com/questions/151969/php-self-vs-this.

 

- Example:

  - Create PHP Console Application Test.php.

 

    Test.php

    <?php

   

      class MyClass {

        public static $prop = "Property";

        public static function myfunc() {

          print("Function - ".self::$prop);

        }

      }

   

      //REFERENCE.

      print(MyClass::myfunc()."\n");

   

    ?>