This site is mobile accessible. Press the "Tap Here" button to use a different font-size.


Smartphone icons created by Freepik - Flaticon

PHP Static Methods

A class can have both static and non-static methods. A static method can be accessed from a method in the same class using the self keyword and double colon (::):

Hello World!

<?php
// define Static Method
class greeting {
  public static function welcome() {
    echo "Hello World!";
  }
  public function __construct() {
    self::welcome();
  }
}

// display the Static Method
new greeting();
?>

A class can have both static and non-static methods. A static method can be accessed from a method in the same class using the self keyword and double colon (::):