PHP支持回調(diào)的函數(shù)有:1、匿名函數(shù),代碼為【$server->on 'Request'】;2、類靜態(tài)方法,代碼為【static function test $req】;3、函數(shù),代碼為【my_onRequest $req】。
PHP支持回調(diào)的函數(shù)有:
1、匿名函數(shù)
$server->on('Request', function ($req, $resp) use ($a, $b, $c) { echo "hello world"; });
可使用use向匿名函數(shù)傳遞參數(shù)
2、類靜態(tài)方法
class A { static function test($req, $resp) { echo "hello world"; } } $server->on('Request', 'A::Test'); $server->on('Request', array('A', 'Test'));
3、函數(shù)
function my_onRequest($req, $resp) { echo "hello world"; } $server->on('Request', 'my_onRequest');
4、對(duì)象方法
class A { function test($req, $resp) { echo "hello world"; } } $object = new A(); $server->on('Request', array($object, 'test'));
相關(guān)學(xué)習(xí)推薦:PHP編程從入門(mén)到精通