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


Smartphone icons created by Freepik - Flaticon

PHP Static Properties

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

3.14159

<?php
// define a Static Property
class pi {
  public static $value=3.14159;
  public function staticValue() {
    return self::$value;
  }
}

// Get static property
$pi = new pi();
echo $pi->staticValue();
?>

Example Explained

Here, we declare a static property: $value. Then, we echo the value of the static property by using the class name, double colon (::), and the property name (without creating a class first).