<?xml version="1.0" encoding="utf-8"?>
<!-- $Revision$ -->
<refentry xml:id="function.is-callable" xmlns="http://docbook.org/ns/docbook">
 <refnamediv>
  <refname>is_callable</refname>
  <refpurpose>
   Verify that a value can be called as a function from the current scope.
  </refpurpose>
 </refnamediv>

 <refsect1 role="description">
  &reftitle.description;
  <methodsynopsis>
   <type>bool</type><methodname>is_callable</methodname>
   <methodparam><type>mixed</type><parameter>value</parameter></methodparam>
   <methodparam choice="opt"><type>bool</type><parameter>syntax_only</parameter><initializer>&false;</initializer></methodparam>
   <methodparam choice="opt"><type>string</type><parameter role="reference">callable_name</parameter><initializer>&null;</initializer></methodparam>
  </methodsynopsis>
  <para>
   Verify that a value is a <type>callable</type>.
  </para>
 </refsect1>

 <refsect1 role="parameters">
  &reftitle.parameters;
  <para>
   <variablelist>
    <varlistentry>
     <term><parameter>value</parameter></term>
     <listitem>
      <para>
       The value to check
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>syntax_only</parameter></term>
     <listitem>
      <para>
       If set to &true; the function only verifies that
       <parameter>value</parameter> 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.
      </para>
     </listitem>
    </varlistentry>
    <varlistentry>
     <term><parameter>callable_name</parameter></term>
     <listitem>
      <para>
       Receives the "callable name".  In the example below it is
       "someClass::someMethod".  Note, however, that despite the implication
       that someClass::SomeMethod() is a callable static method, this is not
       the case.
      </para>
     </listitem>
    </varlistentry>
   </variablelist>
  </para>
 </refsect1>

 <refsect1 role="returnvalues">
  &reftitle.returnvalues;
  <para>
   Returns &true; if <parameter>value</parameter> is callable, &false; 
   otherwise.
  </para>
 </refsect1>

 <refsect1 role="examples">
  &reftitle.examples;
  <para>
   <example>
    <title><function>is_callable</function> example</title>
    <programlisting role="php">
<![CDATA[
<?php
//  How to check a variable to see if it can be called
//  as a function.

//
//  Simple variable containing a function
//

function someFunction() 
{
}

$functionVariable = 'someFunction';

var_dump(is_callable($functionVariable, false, $callable_name));  // bool(true)

echo $callable_name, "\n";  // someFunction

//
//  Array containing a method
//

class someClass {

  function someMethod() 
  {
  }

}

$anObject = new someClass();

$methodVariable = array($anObject, 'someMethod');

var_dump(is_callable($methodVariable, true, $callable_name));  //  bool(true)

echo $callable_name, "\n";  //  someClass::someMethod

?>
]]>
    </programlisting>
   </example>   
   <example>
    <title><function>is_callable</function> and constructors</title>
    <simpara>
     <function>is_callable</function> reports constructors as
     not being callable.
    </simpara>
    <programlisting role="php">
<![CDATA[
<?php

class Foo
{
    public function __construct() {}
    public function foo() {}
}

var_dump(
    is_callable(array('Foo', '__construct')),
    is_callable(array('Foo', 'foo'))
);
]]>
    </programlisting>
    &example.outputs;
    <screen>
<![CDATA[
bool(false)
bool(false)
]]>
    </screen>
   </example>
  </para>   
 </refsect1>

 <refsect1 role="notes">
  &reftitle.notes;
  <simplelist>
   <member>
    An object is always callable if it implements <link linkend="object.invoke">__invoke()</link>,
    and that method is visible in the current scope.
   </member>
   <member>
    A class name is callable if it implements <link linkend="object.callstatic">__callStatic()</link>.
   </member>
   <member>
    If an object implements <link linkend="object.call">__call()</link>, then this function will
    return &true; for any method on that object, even if the method is not defined.
   </member>
   <member>
    This function may trigger autoloading if called with the name of a class.
   </member>
  </simplelist>
 </refsect1>

 <refsect1 role="seealso">
  &reftitle.seealso;
  <para>
   <simplelist>
    <member><function>function_exists</function></member>
    <member><function>method_exists</function></member>
   </simplelist>
  </para>
 </refsect1>

</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->
