How does object-oriented programming (OOP) principles apply to PHP classes and functions in this context?

When applying object-oriented programming principles to PHP classes and functions, it is important to create classes that encapsulate data and behavior, promote code reusability through inheritance, and allow for polymorphism. By organizing code into classes and using objects to represent entities, developers can create more modular and maintainable code.

<?php

// Define a class using OOP principles
class Car {
    private $make;
    private $model;

    public function __construct($make, $model) {
        $this->make = $make;
        $this->model = $model;
    }

    public function getMake() {
        return $this->make;
    }

    public function getModel() {
        return $this->model;
    }
}

// Create an instance of the Car class
$car = new Car('Toyota', 'Camry');

// Access the properties and methods of the Car class
echo 'Make: ' . $car->getMake() . '<br>';
echo 'Model: ' . $car->getModel();
?>