function interface_exists

interface_exists function သည် သတ်မှတ်ထားသော interface သည် လက်ရှိမြင်ကွင်းနယ်ပယ်အတွင်း ရှိ/မရှိ စစ်ဆေးပေးပါသည်။ ပထမဆုံး parameter အဖြစ် string ပုံစံဖြင့် interface အမည်ကို လက်ခံပြီး၊ ဒုတိယမြောက် optional parameter အဖြစ် class များအား auto-load အသုံးပြုရန် လိုအပ်မလိုအပ်ကို ဖော်ပြသော flag တစ်ခုကို လက်ခံပါသည်။

Syntax

phpinterface_exists(string $interface, bool $autoload = true): bool

ဥပမာ

'Countable' interface ရှိ/မရှိ စစ်ကြည့်ပါမည်။

php<?php
  $res = interface_exists('Countable');
  var_dump($res);
?>

Code ကို run ပြီးရရှိသော ရလဒ်။

phptrue

ဥပမာ

မရှိသော interface တစ်ခု၏ ရှိ/မရှိကို စစ်ကြည့်ပါမည်။

php<?php
  $res = interface_exists('NonExistingInterface');
  var_dump($res);
?>

Code ကို run ပြီးရရှိသော ရလဒ်။

phpfalse

ဥပမာ

Auto-load ကို ပိတ်ထားပြီး interface တစ်ခု၏ ရှိ/မရှိကို စစ်ကြည့်ပါမည်။

php<?php
  $res = interface_exists('Iterator', false);
  var_dump($res);
?>

Code ကို run ပြီးရရှိသော ရလဒ်။

phptrue

ဆက်လက်လေ့လာရန်

  • class_exists function,
    သည် class ကို စစ်ဆေးပေးပါသည်။
  • trait_exists function,
    သည် trait ကို စစ်ဆေးပေးပါသည်။
  • get_declared_interfaces function,
    သည် interface များကို ပြန်ပေးပါသည်။
  • class_implements function,
    သည် class ၏ interface များကို ပြန်ပေးပါသည်။