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

3.14159, 3.14159

<?php
// define Static Property
class pi {
  public static $value=3.14159;
}

// class x extends pi
class x extends pi {
  public function xStatic() {
    return parent::$value;
  } 
}

// Get value of static property directly via child class
echo x::$value . ", ";


// Get value of static property via xStatic() method
$x = new x();
echo $x->xStatic();
?>

To call a static property from a child class, use the parent keyword inside the child class: