Skip to content

Commit 32c5528

Browse files
Improve example: is_callable() and constructors (#4274)
1 parent b2a7a5f commit 32c5528

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

reference/var/functions/is-callable.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,11 @@ string(21) "SomeClass::someMethod"
133133
<example>
134134
<title><function>is_callable</function> and constructors</title>
135135
<simpara>
136-
<function>is_callable</function> reports constructors as
137-
not being callable.
136+
Despite the fact that constructors are the methods that are called when
137+
an object is created, they are not static methods and
138+
<function>is_callable</function> will return &false; for them. It's not
139+
possible to use <function>is_callable</function> to check if a class can
140+
be instantiated from the current scope.
138141
</simpara>
139142
<programlisting role="php">
140143
<![CDATA[
@@ -152,6 +155,9 @@ var_dump(
152155
is_callable(['Foo', 'foo'])
153156
);
154157
158+
$foo = new Foo();
159+
var_dump(is_callable([$foo, '__construct']));
160+
155161
?>
156162
]]>
157163
</programlisting>
@@ -160,6 +166,7 @@ var_dump(
160166
<![CDATA[
161167
bool(false)
162168
bool(false)
169+
bool(true)
163170
]]>
164171
</screen>
165172
</example>

0 commit comments

Comments
 (0)