function is_callable

is_callable function သည် ပေးထားသော တန်ဖိုးတစ်ခုကို function အဖြစ် ခေါ်ဆိုနိုင်မနိုင်ကို စစ်ဆေးပေးသည်။ အောက်ပါတို့ဖြစ်ပါက true ပြန်ပေးသည်:

ဖွဲ့စည်းပုံ

phpis_callable(
  mixed $value,
  bool $syntax_only = false,
  string &$callable_name = null
): bool

ဥပမာ

သာမန် function တစ်ခုကို စစ်ဆေးခြင်း:

php<?php
  function test() {}
  $res = is_callable('test');
  var_dump($res);
?>

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

phptrue

ဥပမာ

class method ကို စစ်ဆေးခြင်း:

php<?php
  class MyClass {
    public function method() {}
  }
  $obj = new MyClass();
  $res = is_callable([$obj, 'method']);
  var_dump($res);
?>

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

phptrue

ဥပမာ

မရှိသော function ကို စစ်ဆေးခြင်း:

php<?php
  $res = is_callable('non_existent_function');
  var_dump($res);
?>

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

phpfalse

ဥပမာ

__invoke ပါသည့် object ကို စစ်ဆေးခြင်း:

php<?php
  class Invokable {
    public function __invoke() {}
  }
  $obj = new Invokable();
  $res = is_callable($obj);
  var_dump($res);
?>

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

phptrue

ဒါတွေလဲ ကြည့်ပါ

  • function_exists function,
    သည် function တစ်ခု ရှိ/မရှိကို စစ်ဆေးပေးသည်
  • method_exists function,
    သည် class method တစ်ခု ရှိ/မရှိကို စစ်ဆေးပေးသည်