reference/reflection/reflectionparameter/iscallable.xml
ec2fe9a592f794978114ef5021db9f1d00c2e05d
...
...
@@ -1,17 +1,21 @@
1
1
<?xml version="1.0" encoding="utf-8"?>
2
2
<!-- $Revision$ -->
3
-

4
3
<refentry xml:id="reflectionparameter.iscallable" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>ReflectionParameter::isCallable</refname>
7
6
<refpurpose>Returns whether parameter MUST be callable</refpurpose>
8
7
</refnamediv>
9
8

9
+
<refsynopsisdiv>
10
+
&warn.deprecated.function-8-0-0;
11
+
<para>See the example below for an alternative way to derive this information.</para>
12
+
</refsynopsisdiv>
13
+

10
14
<refsect1 role="description">
11
15
&reftitle.description;
12
-
<methodsynopsis>
16
+
<methodsynopsis role="ReflectionParameter">
13
17
<modifier>public</modifier> <type>bool</type><methodname>ReflectionParameter::isCallable</methodname>
14
-
<void />
18
+
<void/>
15
19
</methodsynopsis>
16
20
<para>
17
21

...
...
@@ -34,9 +38,38 @@
34
38
</para>
35
39
</refsect1>
36
40

41
+
<refsect1 role="examples">
42
+
&reftitle.examples;
43
+
<para>
44
+
<example>
45
+
<title>PHP 8.0.0 equivalent</title>
46
+
<para>
47
+
As of PHP 8.0.0, the following code will report if a type supports callables,
48
+
including as part of a union.
49
+
</para>
50
+
<programlisting role="php">
51
+
<![CDATA[
52
+
<?php
53
+
function declaresCallable(ReflectionParameter $reflectionParameter): bool
54
+
{
55
+
$reflectionType = $reflectionParameter->getType();
37
56

38
-
</refentry>
57
+
if (!$reflectionType) return false;
58
+

59
+
$types = $reflectionType instanceof ReflectionUnionType
60
+
? $reflectionType->getTypes()
61
+
: [$reflectionType];
39
62

63
+
return in_array('callable', array_map(fn(ReflectionNamedType $t) => $t->getName(), $types));
64
+
}
65
+
?>
66
+
]]>
67
+
</programlisting>
68
+
</example>
69
+
</para>
70
+
</refsect1>
71
+

72
+
</refentry>
40
73
<!-- Keep this comment at the end of the file
41
74
Local variables:
42
75
mode: sgml
43
76