reference/funchand/functions/call-user-func.xml
2eb43ad4f41a8c62516abd804721786e50717af6
...
...
@@ -56,9 +56,14 @@ $a = 0;
56
56
call_user_func('increment', $a);
57
57
echo $a."\n";
58
58

59
-
// You can use this instead
59
+
// it is possible to use this instead
60
60
call_user_func_array('increment', array(&$a));
61
61
echo $a."\n";
62
+

63
+
// it is also possible to use a variable function
64
+
$increment = 'increment';
65
+
$increment($a);
66
+
echo $a."\n";
62
67
?>
63
68
]]>
64
69
</programlisting>
...
...
@@ -68,6 +73,7 @@ echo $a."\n";
68
73
Warning: Parameter 1 to increment() expected to be a reference, value given in …
69
74
0
70
75
1
76
+
2
71
77
]]>
72
78
</screen>
73
79
</example>
...
...
@@ -125,8 +131,8 @@ class Foo {
125
131
}
126
132
}
127
133

128
-
call_user_func(__NAMESPACE__ .'\Foo::test'); // As of PHP 5.3.0
129
-
call_user_func(array(__NAMESPACE__ .'\Foo', 'test')); // As of PHP 5.3.0
134
+
call_user_func(__NAMESPACE__ .'\Foo::test');
135
+
call_user_func(array(__NAMESPACE__ .'\Foo', 'test'));
130
136

131
137
?>
132
138
]]>
...
...
@@ -155,7 +161,7 @@ class myclass {
155
161
$classname = "myclass";
156
162

157
163
call_user_func(array($classname, 'say_hello'));
158
-
call_user_func($classname .'::say_hello'); // As of 5.2.3
164
+
call_user_func($classname .'::say_hello');
159
165

160
166
$myobject = new myclass();
161
167

...
...
@@ -178,7 +184,7 @@ Hello!
178
184
<programlisting role="php">
179
185
<![CDATA[
180
186
<?php
181
-
call_user_func(function($arg) { print "[$arg]\n"; }, 'test'); /* As of PHP 5.3.0 */
187
+
call_user_func(function($arg) { print "[$arg]\n"; }, 'test');
182
188
?>
183
189
]]>
184
190
</programlisting>
...
...
@@ -203,6 +209,7 @@ call_user_func(function($arg) { print "[$arg]\n"; }, 'test'); /* As of PHP 5.3.0
203
209
<simplelist>
204
210
<member><function>call_user_func_array</function></member>
205
211
<member><function>is_callable</function></member>
212
+
<member><link linkend="functions.variable-functions">Variable functions</link></member>
206
213
<member><methodname>ReflectionFunction::invoke</methodname></member>
207
214
<member><methodname>ReflectionMethod::invoke</methodname></member>
208
215
</simplelist>
209
216