language/types/callable.xml
c897161ca5a62a887295c695adc161b8fde5d772
...
...
@@ -4,9 +4,7 @@
4
4
<title>Callbacks / Callables</title>
5
5

6
6
<para>
7
-
Callbacks can be denoted by <type>callable</type> type hint as of PHP 5.4.
8
-
This documentation used <type>callback</type> type information for the same
9
-
purpose.
7
+
Callbacks can be denoted by the <type>callable</type> type declaration.
10
8
</para>
11
9

12
10
<para>
...
...
@@ -38,18 +36,29 @@
38
36

39
37
<para>
40
38
Static class methods can also be passed without instantiating an
41
-
<type>object</type> of that class by passing the class name instead of an
42
-
<type>object</type> at index 0.
43
-
As of PHP 5.2.3, it is also possible to pass
39
+
<type>object</type> of that class by either, passing the class name
40
+
instead of an <type>object</type> at index 0, or passing
44
41
<literal>'ClassName::methodName'</literal>.
45
42
</para>
46
43

47
44
<para>
48
45
Apart from common user-defined function,
49
-
<link linkend="functions.anonymous">anonymous functions</link> can also be
46
+
<link linkend="functions.anonymous">anonymous functions</link> and
47
+
<link linkend="functions.arrow">arrow functions</link> can also be
50
48
passed to a callback parameter.
51
49
</para>
52
50

51
+
<note>
52
+
<para>
53
+
As of PHP 8.1.0, anonymous functions can also be created using the <link linkend="functions.first_class_callable_syntax">first class callable syntax</link>.
54
+
</para>
55
+
</note>
56
+

57
+
<para>
58
+
Generally, any object implementing <link linkend="object.invoke">__invoke()</link> can also
59
+
be passed to a callback parameter.
60
+
</para>
61
+

53
62
<para>
54
63
<example>
55
64
<title>
...
...
@@ -81,10 +90,10 @@ call_user_func(array('MyClass', 'myCallbackMethod'));
81
90
$obj = new MyClass();
82
91
call_user_func(array($obj, 'myCallbackMethod'));
83
92

84
-
// Type 4: Static class method call (As of PHP 5.2.3)
93
+
// Type 4: Static class method call
85
94
call_user_func('MyClass::myCallbackMethod');
86
95

87
-
// Type 5: Relative static class method call (As of PHP 5.3.0)
96
+
// Type 5: Relative static class method call
88
97
class A {
89
98
public static function who() {
90
99
echo "A\n";
...
...
@@ -97,9 +106,9 @@ class B extends A {
97
106
}
98
107
}
99
108

100
-
call_user_func(array('B', 'parent::who')); // A
109
+
call_user_func(array('B', 'parent::who')); // A, deprecated as of PHP 8.2.0
101
110

102
-
// Type 6: Objects implementing __invoke can be used as callables (since PHP 5.3)
111
+
// Type 6: Objects implementing __invoke can be used as callables
103
112
class C {
104
113
public function __invoke($name) {
105
114
echo 'Hello ', $name, "\n";
106
115