PHP OOP တွင် class နှင့် object မှတစ်ဆင့် static ကိုရည်ညွှန်းခြင်း

Static properties နှင့် methods များကို class မှတစ်ဆင့် ရော၊ class ၏ object ပါသည့် variable မှတစ်ဆင့်ပါ ရည်ညွှန်းနိုင်ပါသည်။

ဥပမာတစ်ခုဖြင့် ကြည့်ကြပါစို့။ ကျွန်ုပ်တို့တွင် static property တစ်ခုပါသည့် Test class ရှိသည်ဆိုပါစို့။

Test.php<?php
  class Test
  {
    public static $property = 'static';
  }
?>

Class ကို ရည်ညွှန်း၍ static property ၏တန်ဖိုးကို ထုတ်ပြကြပါစို့။

index.php<?php
  echo Test::$property;
?>

ယခု Class ၏ object ကို ရည်ညွှန်း၍ static property ၏တန်ဖိုးကို ထုတ်ပြကြပါစို့။

index.php<?php
  $test = new Test;
  echo $test::$property;
?>
Задание 1

Static method တစ်ခုပါသည့် အောက်ပါ class ကို ပေးထားပါသည်။

Test.php<?php
  class Test
  {
    public static function show()
    {
      return '+++';
    }
  }
?>

ဤ method ကို class method အဖြစ်လည်းကောင်း၊ object method အဖြစ်လည်းကောင်း ခေါ်ယူပါ။