<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.var.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'function.is-callable.php',
    1 => 'is_callable',
    2 => 'Verify that a value can be called as a function from the current scope',
  ),
  'up' => 
  array (
    0 => 'ref.var.php',
    1 => 'Variable handling Functions',
  ),
  'prev' => 
  array (
    0 => 'function.is-bool.php',
    1 => 'is_bool',
  ),
  'next' => 
  array (
    0 => 'function.is-countable.php',
    1 => 'is_countable',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/var/functions/is-callable.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.is-callable" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">is_callable</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">is_callable</span> &mdash; <span class="dc-title">
   Verify that a value can be called as a function from the current scope
  </span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.is-callable-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>is_callable</strong></span>(<span class="methodparam"><span class="type"><a href="language.types.mixed.php" class="type mixed">mixed</a></span> <code class="parameter">$value</code></span>, <span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$syntax_only</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>, <span class="methodparam"><span class="type"><a href="language.types.string.php" class="type string">string</a></span> <code class="parameter reference">&$callable_name</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Verifies that <code class="parameter">value</code> is a <span class="type"><a href="language.types.callable.php" class="type callable">callable</a></span>,
   or that it can be called using the
   <span class="function"><a href="function.call-user-func.php" class="function">call_user_func()</a></span> function.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.is-callable-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">value</code></dt>
     <dd>
      <p class="para">
       The value to be checked.
      </p>
     </dd>
    
    
     <dt><code class="parameter">syntax_only</code></dt>
     <dd>
      <p class="para">
       If set to <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> the function only verifies that
       <code class="parameter">value</code> might be a function or method. It will
       reject any values that are not <a href="language.oop5.magic.php#object.invoke" class="link">invokable</a> objects,
       <span class="classname"><a href="class.closure.php" class="classname">Closure</a></span>, <span class="type"><a href="language.types.string.php" class="type string">string</a></span>s, or <span class="type"><a href="language.types.array.php" class="type array">array</a></span>s that do not have
       a valid structure to be used as a callback. A valid callable array
       has 2 entries, the first of which is an object
       or a string, and the second a string.
      </p>
     </dd>
    
    
     <dt><code class="parameter">callable_name</code></dt>
     <dd>
      <p class="para">
       Receives the &quot;callable name&quot;, e.g.
       <code class="literal">&quot;SomeClass::someMethod&quot;</code>. Note, however, that despite
       the implication that <code class="literal">SomeClass::someMethod()</code> is a
       callable static method, this is not the case.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.is-callable-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> if <code class="parameter">value</code> is callable, <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> 
   otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.is-callable-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>Example #1 Checking whether a string can be called as a function</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">function </span><span style="color: #0000BB">someFunction</span><span style="color: #007700">() {}<br /><br /></span><span style="color: #0000BB">$functionVariable </span><span style="color: #007700">= </span><span style="color: #DD0000">'someFunction'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_callable</span><span style="color: #007700">(</span><span style="color: #0000BB">$functionVariable</span><span style="color: #007700">, </span><span style="color: #0000BB">false</span><span style="color: #007700">, </span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(true)
string(12) &quot;someFunction&quot;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-2">
    <p><strong>Example #2 Checking whether an array can be called as a function</strong></p>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">SomeClass<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">someMethod</span><span style="color: #007700">() {}<br />}<br /><br /></span><span style="color: #0000BB">$anObject </span><span style="color: #007700">= new </span><span style="color: #0000BB">SomeClass</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$methodVariable </span><span style="color: #007700">= [</span><span style="color: #0000BB">$anObject</span><span style="color: #007700">, </span><span style="color: #DD0000">'someMethod'</span><span style="color: #007700">];<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_callable</span><span style="color: #007700">(</span><span style="color: #0000BB">$methodVariable</span><span style="color: #007700">, </span><span style="color: #0000BB">true</span><span style="color: #007700">, </span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">));<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(true)
string(21) &quot;SomeClass::someMethod&quot;</pre>
</div>
    </div>
   </div>
   <div class="example" id="example-3">
    <p><strong>Example #3 <span class="function"><strong>is_callable()</strong></span> and constructors</strong></p>
    <div class="example-contents"><p>
     Despite the fact that constructors are the methods that are called when
     an object is created, they are not static methods and
     <span class="function"><strong>is_callable()</strong></span> will return <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> for them. It&#039;s not
     possible to use <span class="function"><strong>is_callable()</strong></span> to check if a class can
     be instantiated from the current scope.
    </p></div>
    <div class="example-contents">
<div class="annotation-interactive phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /><br /></span><span style="color: #007700">class </span><span style="color: #0000BB">Foo<br /></span><span style="color: #007700">{<br />    public function </span><span style="color: #0000BB">__construct</span><span style="color: #007700">() {}<br /><br />    public function </span><span style="color: #0000BB">foo</span><span style="color: #007700">() {}<br />}<br /><br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(<br />    </span><span style="color: #0000BB">is_callable</span><span style="color: #007700">([</span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'__construct'</span><span style="color: #007700">]),<br />    </span><span style="color: #0000BB">is_callable</span><span style="color: #007700">([</span><span style="color: #DD0000">'Foo'</span><span style="color: #007700">, </span><span style="color: #DD0000">'foo'</span><span style="color: #007700">])<br />);<br /><br /></span><span style="color: #0000BB">$foo </span><span style="color: #007700">= new </span><span style="color: #0000BB">Foo</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">is_callable</span><span style="color: #007700">([</span><span style="color: #0000BB">$foo</span><span style="color: #007700">, </span><span style="color: #DD0000">'__construct'</span><span style="color: #007700">]));<br /><br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>
    </div>

    <div class="example-contents"><p>The above example will output:</p></div>
    <div class="example-contents screen">
<div class="annotation-interactive examplescode"><pre class="examplescode">bool(false)
bool(false)
bool(true)</pre>
</div>
    </div>
   </div>
  </p>   
 </div>


 <div class="refsect1 notes" id="refsect1-function.is-callable-notes">
  <h3 class="title">Notes</h3>
  <ul class="simplelist">
   <li>
    An object is always callable if it implements <a href="language.oop5.magic.php#object.invoke" class="link">__invoke()</a>,
    and that method is visible in the current scope.
   </li>
   <li>
    A class name is callable if it implements <a href="language.oop5.overloading.php#object.callstatic" class="link">__callStatic()</a>.
   </li>
   <li>
    If an object implements <a href="language.oop5.overloading.php#object.call" class="link">__call()</a>, then this function will
    return <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> for any method on that object, even if the method is not defined.
   </li>
   <li>
    This function may trigger autoloading if called with the name of a class.
   </li>
  </ul>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.is-callable-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.call-user-func.php" class="function" rel="rdfs-seeAlso">call_user_func()</a> - Call the callback given by the first parameter</span></li>
    <li><span class="function"><a href="function.function-exists.php" class="function" rel="rdfs-seeAlso">function_exists()</a> - Return true if the given function has been defined</span></li>
    <li><span class="function"><a href="function.method-exists.php" class="function" rel="rdfs-seeAlso">method_exists()</a> - Checks if the class method exists</span></li>
   </ul>
  </p>
 </div>


</div><?php manual_footer($setup); ?>