<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML ><HEAD ><TITLE >is_callable</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.79"><LINK REL="HOME" TITLE="Manual do PHP" HREF="index.html"><LINK REL="UP" TITLE="Variáveis, Funções" HREF="ref.variables.html"><LINK REL="PREVIOUS" TITLE="is_buffer" HREF="function.is-buffer.html"><LINK REL="NEXT" TITLE="is_double" HREF="function.is-double.html"><META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8"></HEAD ><BODY CLASS="refentry" BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE SUMMARY="Header navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >Manual do PHP</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.is-buffer.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.is-double.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.is-callable" ></A >is_callable</H1 ><DIV CLASS="refnamediv" ><A NAME="AEN229919" ></A ><P > (PHP 4 >= 4.0.6, PHP 5)</P >is_callable -- Verify that the contents of a variable can be called as a function </DIV ><DIV CLASS="refsect1" ><A NAME="AEN229922" ></A ><H2 >Description</H2 >bool <B CLASS="methodname" >is_callable</B > ( mixed var [, bool syntax_only [, string &callable_name]] )<BR ></BR ><P > 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 ><P > The <CODE CLASS="parameter" >var</CODE > parameter 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: <TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><PRE CLASS="screen" >array($SomeObject, 'MethodName')</PRE ></TD ></TR ></TABLE > </P ><P > If the <CODE CLASS="parameter" >syntax_only</CODE > argument is <TT CLASS="constant" ><B >TRUE</B ></TT > the function only verifies that <CODE CLASS="parameter" >var</CODE > 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 ><P > The <CODE CLASS="parameter" >callable_name</CODE > argument receives the "callable name". In the example below it's "someClass:someMethod". Note, however, that despite the implication that someClass::SomeMethod() is a callable static method, this is not the case. </P ><DIV CLASS="informalexample" ><P ></P ><A NAME="AEN229946" ></A ><TABLE BORDER="0" BGCOLOR="#E0E0E0" CELLPADDING="5" ><TR ><TD ><code><font color="#000000"> <font color="#0000BB"><?php<br /></font><font color="#FF8000">// How to check a variable to see if it can be called<br />// as a function.<br /><br />//<br />// Simple variable containing a function<br />//<br /><br /></font><font color="#007700">function </font><font color="#0000BB">someFunction</font><font color="#007700">() <br />{<br />}<br /><br /></font><font color="#0000BB">$functionVariable </font><font color="#007700">= </font><font color="#DD0000">'someFunction'</font><font color="#007700">;<br /><br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">is_callable</font><font color="#007700">(</font><font color="#0000BB">$functionVariable</font><font color="#007700">, </font><font color="#0000BB">false</font><font color="#007700">, </font><font color="#0000BB">$callable_name</font><font color="#007700">)); </font><font color="#FF8000">// bool(true)<br /><br /></font><font color="#007700">echo </font><font color="#0000BB">$callable_name</font><font color="#007700">, </font><font color="#DD0000">"\n"</font><font color="#007700">; </font><font color="#FF8000">// someFunction<br /><br />//<br />// Array containing a method<br />//<br /><br /></font><font color="#007700">class </font><font color="#0000BB">someClass </font><font color="#007700">{<br /><br /> function </font><font color="#0000BB">someMethod</font><font color="#007700">() <br /> {<br /> }<br /><br />}<br /><br /></font><font color="#0000BB">$anObject </font><font color="#007700">= new </font><font color="#0000BB">someClass</font><font color="#007700">();<br /><br /></font><font color="#0000BB">$methodVariable </font><font color="#007700">= array(</font><font color="#0000BB">$anObject</font><font color="#007700">, </font><font color="#DD0000">'someMethod'</font><font color="#007700">);<br /><br /></font><font color="#0000BB">var_dump</font><font color="#007700">(</font><font color="#0000BB">is_callable</font><font color="#007700">(</font><font color="#0000BB">$methodVariable</font><font color="#007700">, </font><font color="#0000BB">true</font><font color="#007700">, </font><font color="#0000BB">$callable_name</font><font color="#007700">)); </font><font color="#FF8000">// bool(true)<br /><br /></font><font color="#007700">echo </font><font color="#0000BB">$callable_name</font><font color="#007700">, </font><font color="#DD0000">"\n"</font><font color="#007700">; </font><font color="#FF8000">// someClass:someMethod<br /><br /></font><font color="#0000BB">?></font> </font> </code></TD ></TR ></TABLE ><P ></P ></DIV ><P > See also <A HREF="function.function-exists.html" ><B CLASS="function" >function_exists()</B ></A > and <A HREF="function.method-exists.html" ><B CLASS="function" >method_exists()</B ></A >. </P ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE SUMMARY="Footer navigation table" WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.is-buffer.html" ACCESSKEY="P" >Anterior</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="index.html" ACCESSKEY="H" >Principal</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.is-double.html" ACCESSKEY="N" >Próxima</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >is_buffer</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.variables.html" ACCESSKEY="U" >Acima</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >is_double</TD ></TR ></TABLE ></DIV ></BODY ></HTML >