we can use static properties inside object methods (non-static methods)
We can use static properties inside non-static methods but we can't use
$this
inside static methods
class Circle {
    public static $pi = 3.1415926535;
    public $radius;
    
    public function __construct($radius) {
        $this->radius = $radius;
    }
    
    public function getArea() {
        return pow($this->radius, 2) * self::$pi;
    }
    
    public function getPerimeter() {
        return $this->radius * 2 * self::$pi;
    }
}

$circle1 = new Circle(5);
echo "\nArea: " . $circle1->getArea();
echo "\nPerimeter: " . $circle1->getPerimeter();
by Valeri Tandilashvili
4 years ago
PHP
OOP
3
Pro tip: use ```triple backticks around text``` to write in code fences