downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | links | conferences | my php.net

search for in the

Our source is open

The syntax highlighted source is automatically generated by PHP from the plaintext script. If you're interested in what's behind the several functions we used, you can always take a look at the source of the following files:

Of course, if you want to see the source of this page, we have it available. You can also browse the SVN repository for this website on svn.php.net.

Source of: /manual/en/function.is-callable.php

<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = 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',
  ),
 
'up' =>
  array (
   
0 => 'ref.var.php',
   
1 => 'Variable handling Functions',
  ),
 
'prev' =>
  array (
   
0 => 'function.is-buffer.php',
   
1 => 'is_buffer',
  ),
 
'next' =>
  array (
   
0 => 'function.is-double.php',
   
1 => 'is_double',
  ),
);
$setup["toc"] = $TOC;
$setup["parents"] = $PARENTS;
manual_setup($setup);

manual_header();
?>
<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)</p><p class="refpurpose"><span class="refname">is_callable</span> &mdash; <span class="dc-title">
   Verify that the contents of a variable can be called as a function
  </span></p>

 </div>

 <a name="function.is-callable.description"></a><div class="refsect1 description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><b>is_callable</b></span>
    ( <span class="methodparam"><span class="type"><a href="language.pseudo-types.php#language.types.callback" class="type callback">callback</a></span> <tt class="parameter">$name</tt></span>
   [, <span class="methodparam"><span class="type">bool</span> <tt class="parameter">$syntax_only</tt><span class="initializer"> = false</span></span>
   [, <span class="methodparam"><span class="type">string</span> <tt class="parameter reference">&amp;$callable_name</tt></span>
  ]] )</div>

  <p class="para rdfs-comment">
   Verify that the contents of a variable can be called as a function.
   This can check that a simple variable contains the name of a valid
   function, or that an array contains a properly encoded object and
   function name.
  </p>
 </div>


 <a name="function.is-callable.parameters"></a><div class="refsect1 parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   </p><dl>

    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Can be either the name of a function stored in a string variable, or
       an object and the name of a method within the object, like this:
       <div class="example-contents screen">array($SomeObject, &#039;MethodName&#039;)</div>
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">syntax_only</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       If set to <b><tt class="constant">TRUE</tt></b> the function only verifies that
       <i><tt class="parameter">name</tt></i>
 might be a function or method. It will only
       reject simple variables that are not strings, or an array that does
       not have a valid structure to be used as a callback. The valid ones
       are supposed to have only 2 entries, the first of which is an object
       or a string, and the second a string.
      </p>
     </dd>

   
    <dt class="varlistentry">

     <span class="term"><i><tt class="parameter">callable_name</tt></i>
</span>

     </dt><dd class="listitem">

      <p class="para">
       Receives the &quot;callable name&quot;.  In the example below it is
       &quot;someClass::someMethod&quot;.  Note, however, that despite the implication
       that someClass::SomeMethod() is a callable static method, this is not
       the case.
      </p>
     </dd>

   
   </dl>
<p>
  </p>
 </div>


 <a name="function.is-callable.returnvalues"></a><div class="refsect1 returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <b><tt class="constant">TRUE</tt></b> if <i><tt class="parameter">name</tt></i>
 is callable, <b><tt class="constant">FALSE</tt></b>
   otherwise.
  </p>
 </div>


 <a name="function.is-callable.examples"></a><div class="refsect1 examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   </p><div class="example">
    <p><b>Example #1 <b>is_callable()</b> example</b></p>
    <div class="example-contents programlisting">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;&nbsp;How&nbsp;to&nbsp;check&nbsp;a&nbsp;variable&nbsp;to&nbsp;see&nbsp;if&nbsp;it&nbsp;can&nbsp;be&nbsp;called<br />//&nbsp;&nbsp;as&nbsp;a&nbsp;function.<br /><br />//<br />//&nbsp;&nbsp;Simple&nbsp;variable&nbsp;containing&nbsp;a&nbsp;function<br />//<br /><br /></span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">someFunction</span><span style="color: #007700">()&nbsp;<br />{<br />}<br /><br /></span><span style="color: #0000BB">$functionVariable&nbsp;</span><span style="color: #007700">=&nbsp;</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">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">));&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;bool(true)<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;someFunction<br /><br />//<br />//&nbsp;&nbsp;Array&nbsp;containing&nbsp;a&nbsp;method<br />//<br /><br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">someClass&nbsp;</span><span style="color: #007700">{<br /><br />&nbsp;&nbsp;function&nbsp;</span><span style="color: #0000BB">someMethod</span><span style="color: #007700">()&nbsp;<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;}<br /><br />}<br /><br /></span><span style="color: #0000BB">$anObject&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">someClass</span><span style="color: #007700">();<br /><br /></span><span style="color: #0000BB">$methodVariable&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">$anObject</span><span style="color: #007700">,&nbsp;</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">,&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">));&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;&nbsp;bool(true)<br /><br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">$callable_name</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;&nbsp;someClass::someMethod<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div><p>  
  </p>  
 </div>


 <a name="function.is-callable.seealso"></a><div class="refsect1 seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
   </p><ul class="simplelist">
    <li class="member"><a href="function.function-exists.php" class="function" rel="rdfs-seeAlso">function_exists()</a> - Return TRUE if the given function has been defined</li>
    <li class="member"><a href="function.method-exists.php" class="function" rel="rdfs-seeAlso">method_exists()</a> - Checks if the class method exists</li>
   </ul><p>
  </p>
 </div>


</div><?php manual_footer(); ?>
 
show source | credits | sitemap | contact | advertising | mirror sites