reference/reflection/reflectionparameter/isarray.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.isarray" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
5
4
<refnamediv>
6
5
<refname>ReflectionParameter::isArray</refname>
7
6
<refpurpose>Checks if parameter expects an array</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::isArray</methodname>
14
-
<void />
18
+
<void/>
15
19
</methodsynopsis>
16
20
<para>
17
21
Checks if the parameter expects an array.
...
...
@@ -30,6 +34,37 @@
30
34
</para>
31
35
</refsect1>
32
36

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

53
+
if (!$reflectionType) return false;
54
+

55
+
$types = $reflectionType instanceof ReflectionUnionType
56
+
? $reflectionType->getTypes()
57
+
: [$reflectionType];
58
+

59
+
return in_array('array', array_map(fn(ReflectionNamedType $t) => $t->getName(), $types));
60
+
}
61
+
?>
62
+
]]>
63
+
</programlisting>
64
+
</example>
65
+
</para>
66
+
</refsect1>
67
+

33
68
<refsect1 role="seealso">
34
69
&reftitle.seealso;
35
70
<para>
...
...
@@ -40,7 +75,6 @@
40
75
</refsect1>
41
76

42
77
</refentry>
43
-

44
78
<!-- Keep this comment at the end of the file
45
79
Local variables:
46
80
mode: sgml
47
81