class Car { public $brand; public $model; public function __construct($brand, $model) { $this->brand = $brand; $this->model = $model; } } $car = new Car("Toyota", "Camry"); echo $car->brand; // Output: Toyota echo $car->model; // Output: Camry
class Person { public $name; public $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $person = new Person("John", 30); echo $person->name; // Output: John echo $person->age; // Output: 30This example creates a Person class with two properties, name and age, and a constructor method that takes two arguments ($name and $age) and assigns them to their respective class properties. We then create an object of this class with the values "John" and 30 and output the values of its properties using the echo statement. __construct is a built-in helper method in PHP, part of the core language. It does not belong to any specific package or library.