Skip to content

Commit 4806183

Browse files
Redesign is_callable() page (#4145)
1 parent 55e2079 commit 4806183

File tree

1 file changed

+44
-27
lines changed

1 file changed

+44
-27
lines changed

reference/var/functions/is-callable.xml

Lines changed: 44 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
<methodparam choice="opt"><type>string</type><parameter role="reference">callable_name</parameter><initializer>&null;</initializer></methodparam>
1818
</methodsynopsis>
1919
<para>
20-
Verify that a value is a <type>callable</type>.
20+
Verifies that <parameter>value</parameter> is a <type>callable</type>,
21+
or that it can be called using the
22+
<function>call_user_func</function> function.
2123
</para>
2224
</refsect1>
2325

@@ -29,7 +31,7 @@
2931
<term><parameter>value</parameter></term>
3032
<listitem>
3133
<para>
32-
The value to check
34+
The value to be checked.
3335
</para>
3436
</listitem>
3537
</varlistentry>
@@ -38,10 +40,10 @@
3840
<listitem>
3941
<para>
4042
If set to &true; the function only verifies that
41-
<parameter>value</parameter> might be a function or method. It will only
42-
reject simple variables that are not strings, or an array that does
43-
not have a valid structure to be used as a callback. The valid ones
44-
are supposed to have only 2 entries, the first of which is an object
43+
<parameter>value</parameter> might be a function or method. It will
44+
reject any values that are neither callable objects, strings nor arrays
45+
with a valid structure to be used as a callback. A valid callable array
46+
has 2 entries, the first of which is an object
4547
or a string, and the second a string.
4648
</para>
4749
</listitem>
@@ -50,10 +52,10 @@
5052
<term><parameter>callable_name</parameter></term>
5153
<listitem>
5254
<para>
53-
Receives the "callable name". In the example below it is
54-
"someClass::someMethod". Note, however, that despite the implication
55-
that someClass::SomeMethod() is a callable static method, this is not
56-
the case.
55+
Receives the "callable name", e.g.
56+
<literal>"SomeClass::someMethod"</literal>. Note, however, that despite
57+
the implication that <literal>SomeClass::someMethod()</literal> is a
58+
callable static method, this is not the case.
5759
</para>
5860
</listitem>
5961
</varlistentry>
@@ -73,46 +75,60 @@
7375
&reftitle.examples;
7476
<para>
7577
<example>
76-
<title><function>is_callable</function> example</title>
78+
<title>Checking whether a string can be called as a function</title>
7779
<programlisting role="php">
7880
<![CDATA[
7981
<?php
80-
// How to check a variable to see if it can be called
81-
// as a function.
82-
83-
//
84-
// Simple variable containing a function
85-
//
8682
8783
function someFunction() {}
8884
8985
$functionVariable = 'someFunction';
9086
91-
var_dump(is_callable($functionVariable, false, $callable_name)); // bool(true)
87+
var_dump(is_callable($functionVariable, false, $callable_name));
9288
93-
echo $callable_name, "\n"; // someFunction
89+
var_dump($callable_name);
9490
95-
//
96-
// Array containing a method
97-
//
91+
?>
92+
]]>
93+
</programlisting>
94+
&example.outputs;
95+
<screen>
96+
<![CDATA[
97+
bool(true)
98+
string(12) "someFunction"
99+
]]>
100+
</screen>
101+
</example>
102+
<example>
103+
<title>Checking whether an array can be called as a function</title>
104+
<programlisting role="php">
105+
<![CDATA[
106+
<?php
98107
99-
class someClass
108+
class SomeClass
100109
{
101110
public function someMethod() {}
102111
}
103112
104-
$anObject = new someClass();
113+
$anObject = new SomeClass();
105114
106115
$methodVariable = [$anObject, 'someMethod'];
107116
108-
var_dump(is_callable($methodVariable, true, $callable_name)); // bool(true)
117+
var_dump(is_callable($methodVariable, true, $callable_name));
109118
110-
echo $callable_name, "\n"; // someClass::someMethod
119+
var_dump($callable_name);
111120
112121
?>
113122
]]>
114123
</programlisting>
115-
</example>
124+
&example.outputs;
125+
<screen>
126+
<![CDATA[
127+
bool(true)
128+
string(21) "SomeClass::someMethod"
129+
]]>
130+
</screen>
131+
</example>
116132
<example>
117133
<title><function>is_callable</function> and constructors</title>
118134
<simpara>
@@ -173,6 +189,7 @@ bool(false)
173189
&reftitle.seealso;
174190
<para>
175191
<simplelist>
192+
<member><function>call_user_func</function></member>
176193
<member><function>function_exists</function></member>
177194
<member><function>method_exists</function></member>
178195
</simplelist>

0 commit comments

Comments
 (0)