Source Code:
(back to article)
<?php // Example 1 class Car { public $model; public $color; public function __construct($model, $color) { $this->model = $model . PHP_EOL; $this->color = $color; } public function honk() { return "Beep beep!" . PHP_EOL; } } $myCar = new Car("Tesla", "red"); echo $myCar->model; // Output: Tesla echo $myCar->honk(); // Output: Beep beep! // Example 2 class Math { public static function add($a, $b) { return $a + $b . PHP_EOL; } public static function multiply($a, $b) { return $a * $b . PHP_EOL; } } echo Math::add(5, 10); // Output: 15 echo Math::multiply(5, 10); // Output: 50
Result:
Report an issue