reference/var/functions/is-callable.xml
83a17a7324c2597bd6385148abf19f76127229f5
...
...
@@ -4,7 +4,7 @@
4
4
<refnamediv>
5
5
<refname>is_callable</refname>
6
6
<refpurpose>
7
-
Verify that the contents of a variable can be called as a function
7
+
Verify that a value can be called as a function from the current scope.
8
8
</refpurpose>
9
9
</refnamediv>
10
10

...
...
@@ -12,15 +12,12 @@
12
12
&reftitle.description;
13
13
<methodsynopsis>
14
14
<type>bool</type><methodname>is_callable</methodname>
15
-
<methodparam><type>mixed</type><parameter>var</parameter></methodparam>
16
-
<methodparam choice="opt"><type>bool</type><parameter>syntax_only</parameter><initializer>false</initializer></methodparam>
17
-
<methodparam choice="opt"><type>string</type><parameter role="reference">callable_name</parameter></methodparam>
15
+
<methodparam><type>mixed</type><parameter>value</parameter></methodparam>
16
+
<methodparam choice="opt"><type>bool</type><parameter>syntax_only</parameter><initializer>&false;</initializer></methodparam>
17
+
<methodparam choice="opt"><type>string</type><parameter role="reference">callable_name</parameter><initializer>&null;</initializer></methodparam>
18
18
</methodsynopsis>
19
19
<para>
20
-
Verify that the contents of a variable can be called as a function.
21
-
This can check that a simple variable contains the name of a valid
22
-
function, or that an array contains a properly encoded object and
23
-
function name.
20
+
Verify that a value is a <type>callable</type>.
24
21
</para>
25
22
</refsect1>
26
23

...
...
@@ -29,7 +26,7 @@
29
26
<para>
30
27
<variablelist>
31
28
<varlistentry>
32
-
<term><parameter>var</parameter></term>
29
+
<term><parameter>value</parameter></term>
33
30
<listitem>
34
31
<para>
35
32
The value to check
...
...
@@ -41,7 +38,7 @@
41
38
<listitem>
42
39
<para>
43
40
If set to &true; the function only verifies that
44
-
<parameter>name</parameter> might be a function or method. It will only
41
+
<parameter>value</parameter> might be a function or method. It will only
45
42
reject simple variables that are not strings, or an array that does
46
43
not have a valid structure to be used as a callback. The valid ones
47
44
are supposed to have only 2 entries, the first of which is an object
...
...
@@ -67,7 +64,7 @@
67
64
<refsect1 role="returnvalues">
68
65
&reftitle.returnvalues;
69
66
<para>
70
-
Returns &true; if <parameter>var</parameter> is callable, &false;
67
+
Returns &true; if <parameter>value</parameter> is callable, &false;
71
68
otherwise.
72
69
</para>
73
70
</refsect1>
...
...
@@ -121,9 +118,59 @@ echo $callable_name, "\n"; // someClass::someMethod
121
118
]]>
122
119
</programlisting>
123
120
</example>
121
+
<example>
122
+
<title><function>is_callable</function> and constructors</title>
123
+
<simpara>
124
+
<function>is_callable</function> reports constructors as
125
+
not being callable.
126
+
</simpara>
127
+
<programlisting role="php">
128
+
<![CDATA[
129
+
<?php
130
+

131
+
class Foo
132
+
{
133
+
public function __construct() {}
134
+
public function foo() {}
135
+
}
136
+

137
+
var_dump(
138
+
is_callable(array('Foo', '__construct')),
139
+
is_callable(array('Foo', 'foo'))
140
+
);
141
+
]]>
142
+
</programlisting>
143
+
&example.outputs;
144
+
<screen>
145
+
<![CDATA[
146
+
bool(false)
147
+
bool(false)
148
+
]]>
149
+
</screen>
150
+
</example>
124
151
</para>
125
152
</refsect1>
126
153

154
+
<refsect1 role="notes">
155
+
&reftitle.notes;
156
+
<simplelist>
157
+
<member>
158
+
An object is always callable if it implements <link linkend="object.invoke">__invoke()</link>,
159
+
and that method is visible in the current scope.
160
+
</member>
161
+
<member>
162
+
A class name is callable if it implements <link linkend="object.callstatic">__callStatic()</link>.
163
+
</member>
164
+
<member>
165
+
If an object implements <link linkend="object.call">__call()</link>, then this function will
166
+
return &true; for any method on that object, even if the method is not defined.
167
+
</member>
168
+
<member>
169
+
This function may trigger autoloading if called with the name of a class.
170
+
</member>
171
+
</simplelist>
172
+
</refsect1>
173
+

127
174
<refsect1 role="seealso">
128
175
&reftitle.seealso;
129
176
<para>
...
...
@@ -135,7 +182,6 @@ echo $callable_name, "\n"; // someClass::someMethod
135
182
</refsect1>
136
183

137
184
</refentry>
138
-

139
185
<!-- Keep this comment at the end of the file
140
186
Local variables:
141
187
mode: sgml
142
188