1. Classes and Objectes.

I am a Senior Web Developer | Software Engineer (Laravel, WordPress) who is experienced for more than 5 years.
Classes are a blueprint for creating objects. They define properties(attributes) and methods(functions) that objects of classes will have.
Objects are instances of classes. its created using the ‘new’ keyword.
A constructor is a special method within a class that is automatically called when an object of that class is created. Its main purpose is to initialize the object's properties or run any tasks needed before the object can be used in PHP, the constructor method is defined like this " __construct()"
<?php
class Car {
//*** Properties*/
public $brand;
public $model;
public $year;
//*** Constructor method*/
public function __construct($brand, $model, $year) {
$this->brand = $brand;
$this->model = $model;
$this->year = $year;
}
//*** Method */
public function getInfo() {
return $this->brand . ' ' . $this->model . ' (' . $this->year . ')';
}
}
//*** Create an instance of the Car class */
$car1 = new Car('BMW', 'M3', 2022);
$car2 = new Car('Honda', 'Civic', 2021);
//*** Accessing object properties */
echo $car1->brand; //*** BMW M3 (2022)*/
echo $car2->getInfo(); //*** Honda Civic (2021) */
?>



