Let's keep it simple
A class is a blueprint that bundles together data and behavior. Property visibility is controlled with public/private/protected, and the constructor accepts the initial state an object needs.
php
<?php
class Course
{
public function __construct(
private string $title,
private int $lessons
) {}
public function summary(): string
{
return "$this->title — $this->lessons lessons";
}
}
$course = new Course('PHP', 30);
echo $course->summary();You should see
PHP — 30 lessonsTry it yourself
Build a BankAccount class with name and balance, and make its deposit() method accept only positive amounts.