Source Code:
(back to article)
<?php // Example 1 class Circle { const PI = 3.14; public $radius; public function __construct($radius) { $this->radius = $radius; } public function getArea() { return self::PI * $this->radius * $this->radius; } } $myCircle = new Circle(5); echo "Area of circle: " . $myCircle->getArea() . PHP_EOL; // Output: Area of circle: 78.5 // Example 2 const MY_NAME = "John"; echo "My name is " . MY_NAME; // Output: My name is John
Result:
Report an issue