ရိုးရိုးလေး ရှင်းပြမယ်
Class သည် data နှင့် behavior ကိုစုစည်းထားသော blueprint ဖြစ်သည်။ Property visibility ကို public/private/protected ဖြင့်ထိန်းချုပ်ပြီး constructor တွင် object တစ်ခုလိုအပ်သော initial state ကိုလက်ခံပါ။
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 lessonsလက်တွေ့စမ်းကြည့်ရန်
name နှင့် balance ပါသော BankAccount class တည်ဆောက်ပြီး deposit() method တွင် positive amount ကိုသာလက်ခံပါ။