PHP支持回调的函数有哪些?

首页 编程分享 PHP丨JAVA丨OTHER 正文

coldplay.xixi 转载 编程分享 2020-06-30 23:36:06

简介 PHP支持回调的函数有:1、匿名函数,代码为【$server->on 'Request'】;2、类静态方法,代码为【static function test $req】;3、函数,代码为【my_onRequest $req】。


PHP支持回调的函数有:

1、匿名函数

$server->on('Request', function ($req, $resp) use ($a, $b, $c) {
    echo "hello world";
});
可使用use向匿名函数传递参数

2、类静态方法

class A
{
    static function test($req, $resp)
    {
        echo "hello world";
    }
}
$server->on('Request', 'A::Test');
$server->on('Request', array('A', 'Test'));

3、函数

function my_onRequest($req, $resp)
{
    echo "hello world";
}
$server->on('Request', 'my_onRequest');

4、对象方法

class A
{
    function test($req, $resp)
    {
        echo "hello world";
    }
}
$object = new A();
$server->on('Request', array($object, 'test'));
相关学习推荐:

转载链接:http://www.php.cn//php-weizijiaocheng-453570.html


Tags:


本篇评论 —— 揽流光,涤眉霜,清露烈酒一口话苍茫。


    声明:参照站内规则,不文明言论将会删除,谢谢合作。


      最新评论




ABOUT ME

Blogger:袅袅牧童 | Arkin

Ido:PHP攻城狮

WeChat:nnmutong

Email:nnmutong@icloud.com

标签云