PHP တွင် OOP static နှင့်ပေါင်းစပ်အသုံးပြုခြင်း
Class တစ်ခုမှာ static properties တွေ၊ methods တွေရော၊ ပုံမှန် properties တွေ၊ methods တွေပါ ပါဝင်နိုင်ပါတယ်။
ဥပမာတစ်ခုနဲ့ ကြည့်ရအောင်။ ကျွန်တော်တို့မှာ Test class တစ်ခုရှိတယ်ဆိုပါစို့၊ အဲဒီ class မှာ static property တစ်ခုရော၊ ပုံမှန် property တစ်ခုရော တစ်ခါတည်းပါနေပါတယ်။
<?php
class Test
{
public static $staticProperty = 'static';
public $usualProperty = 'usual';
}
?>
ကဲ ပုံမှန် class property နဲ့ အလုပ်လုပ်ကြည့်ရအောင်။
<?php
$test = new Test;
echo $test->usualProperty;
?>
အခု static property ကို အသုံးပြုကြည့်ရအောင်။
<?php
echo Test::$staticProperty;
?>
ပုံမှန် method တစ်ခုရော static method တစ်ခုရော ပါတဲ့ class တစ်ခုကို ဖန်တီးပါ။