2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2005-08-29 15:46:34 +00:00
|
|
|
<!-- $Revision: 1.10 $ -->
|
2002-04-15 00:12:54 +00:00
|
|
|
<!-- splitted from ./en/functions/var.xml, last change in rev 1.87 -->
|
|
|
|
<refentry id="function.is-callable">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>is_callable</refname>
|
|
|
|
<refpurpose>
|
2003-07-04 21:43:55 +00:00
|
|
|
Verify that the contents of a variable can be called as a function
|
2002-04-15 00:12:54 +00:00
|
|
|
</refpurpose>
|
|
|
|
</refnamediv>
|
|
|
|
<refsect1>
|
|
|
|
<title>Description</title>
|
|
|
|
<methodsynopsis>
|
|
|
|
<type>bool</type><methodname>is_callable</methodname>
|
|
|
|
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
|
|
|
|
<methodparam choice="opt"><type>bool</type><parameter>syntax_only</parameter></methodparam>
|
2004-11-10 08:30:50 +00:00
|
|
|
<methodparam choice="opt"><type>string</type><parameter role="reference">callable_name</parameter></methodparam>
|
2002-04-15 00:12:54 +00:00
|
|
|
</methodsynopsis>
|
|
|
|
<para>
|
2003-07-04 21:43:55 +00:00
|
|
|
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.
|
2002-04-15 00:12:54 +00:00
|
|
|
</para>
|
2002-11-18 07:59:04 +00:00
|
|
|
<para>
|
2003-12-15 16:55:22 +00:00
|
|
|
The <parameter>var</parameter> parameter can be either the name of a function stored in
|
2003-07-04 21:43:55 +00:00
|
|
|
a string variable, or an object and the name of a method within the
|
|
|
|
object, like this:
|
2003-12-15 16:55:22 +00:00
|
|
|
<screen>array($SomeObject, 'MethodName')</screen>
|
2003-07-04 21:43:55 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
If the <parameter>syntax_only</parameter> argument is &true; the
|
|
|
|
function only verifies that <parameter>var</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>
|
|
|
|
<para>
|
|
|
|
The <parameter>callable_name</parameter> 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.
|
|
|
|
</para>
|
|
|
|
<informalexample>
|
2003-08-16 18:59:12 +00:00
|
|
|
<programlisting role="php">
|
2002-11-18 07:59:04 +00:00
|
|
|
<![CDATA[
|
2003-12-15 16:55:22 +00:00
|
|
|
<?php
|
2003-07-04 21:43:55 +00:00
|
|
|
// How to check a variable to see if it can be called
|
|
|
|
// as a function.
|
|
|
|
|
|
|
|
//
|
|
|
|
// Simple variable containing a function
|
|
|
|
//
|
|
|
|
|
2004-01-15 12:43:50 +00:00
|
|
|
function someFunction()
|
|
|
|
{
|
2002-11-18 07:59:04 +00:00
|
|
|
}
|
|
|
|
|
2003-07-04 21:43:55 +00:00
|
|
|
$functionVariable = 'someFunction';
|
|
|
|
|
2003-12-15 16:55:22 +00:00
|
|
|
var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true)
|
2002-11-18 07:59:04 +00:00
|
|
|
|
2003-07-04 21:43:55 +00:00
|
|
|
echo $callable_name, "\n"; // someFunction
|
|
|
|
|
|
|
|
//
|
|
|
|
// Array containing a method
|
|
|
|
//
|
|
|
|
|
|
|
|
class someClass {
|
|
|
|
|
2004-01-15 12:43:50 +00:00
|
|
|
function someMethod()
|
|
|
|
{
|
2003-07-04 21:43:55 +00:00
|
|
|
}
|
2002-11-18 07:59:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2003-07-04 21:43:55 +00:00
|
|
|
$anObject = new someClass();
|
|
|
|
|
2003-12-15 16:55:22 +00:00
|
|
|
$methodVariable = array($anObject, 'someMethod');
|
2003-07-04 21:43:55 +00:00
|
|
|
|
2003-12-15 16:55:22 +00:00
|
|
|
var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true)
|
2003-07-04 21:43:55 +00:00
|
|
|
|
|
|
|
echo $callable_name, "\n"; // someClass:someMethod
|
2002-11-18 07:59:04 +00:00
|
|
|
|
|
|
|
?>
|
|
|
|
]]>
|
2003-07-04 21:43:55 +00:00
|
|
|
</programlisting>
|
|
|
|
</informalexample>
|
2005-08-29 15:46:34 +00:00
|
|
|
<para>
|
|
|
|
See also <function>function_exists</function> and
|
|
|
|
<function>method_exists</function>.
|
|
|
|
</para>
|
2002-04-15 00:12:54 +00:00
|
|
|
</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:"../../../../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
|
|
|
|
-->
|