PHP Object-Oriented Programming (Classes & Objects)
Defines a PHP class with properties, constructor, and methods.
<?php
class Car {
public $brand;
public $model;
public function __construct($brand, $model) {
$this->brand = $brand;
$this->model = $model;
}
public function getDetails() {
return "Car: {$this->brand} {$this->model}";
}
}
$myCar = new Car("Toyota", "Corolla");
echo $myCar->getDetails() . "\n";
?>Car: Toyota Corolla