1. 函數說明
呼叫回調函數。原型: mixed call_user_func ( callable <code><span><?php</span><span><span>function</span><span>addone</span><span>(&<span>$num</span>)</span> {</span><span>$num</span> ++;
}
<span>$num</span> = <span>0</span>;
call_user_func(<span>'addone'</span>, <span>$num</span>);
<span>echo</span><span>"num : "</span> . <span>$num</span> . <span>"\n"</span>;
call_user_func_array(<span>'addone'</span>, <span>array</span>(&<span>$num</span>) );
<span>echo</span><span>"num : "</span> . <span>$num</span> . <span>"\n"</span>;
<span>?></span></code>
命名空間的使用。
<code><span><?php</span><span>namespace</span><span>Foobar</span>; <span><span>class</span><span>Foo</span> {</span><span>static</span><span>public</span><span><span>function</span><span>test</span><span>()</span> {</span><span>print</span><span>"Hello world!\n"</span>; } } call_user_func(<span>__NAMESPACE__</span> .<span>'\Foo::test'</span>); call_user_func(<span>array</span>(<span>__NAMESPACE__</span> .<span>'\Foo'</span>, <span>'test'</span>)); <span>?></span></code>
<code><span><?php</span><span><span>class</span><span>myclass</span> {</span><span>static</span><span><span>function</span><span>test</span><span>()</span> {</span><span>echo</span><span>"Hello world!\n"</span>; } } <span>$classname</span> = <span>"myclass"</span>; call_user_func(<span>array</span>(<span>$classname</span>, <span>'test'</span>)); <span>$myobject</span> = <span>new</span> myclass(); call_user_func(<span>array</span>(<span>$myobject</span>, <span>'test'</span>)); <span>?></span></code>