फ़ंक्शन is_callable

फ़ंक्शन is_callable जाँचता है कि क्या पारित मान को फ़ंक्शन के रूप में कॉल किया जा सकता है। यह true लौटाता है, यदि मान निम्न है:

सिंटैक्स

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

उदाहरण

सामान्य फ़ंक्शन की जाँच:

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

कोड निष्पादन का परिणाम:

phptrue

उदाहरण

क्लास मेथड की जाँच:

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

कोड निष्पादन का परिणाम:

phptrue

उदाहरण

गैर-मौजूद फ़ंक्शन की जाँच:

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

कोड निष्पादन का परिणाम:

phpfalse

उदाहरण

__invoke वाली ऑब्जेक्ट की जाँच:

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

कोड निष्पादन का परिणाम:

phptrue

यह भी देखें

  • फ़ंक्शन function_exists,
    जो फ़ंक्शन के अस्तित्व की जाँच करता है
  • फ़ंक्शन method_exists,
    जो क्लास मेथड के अस्तित्व की जाँच करता है