首页 > 技术 > 正文

php的4种回调函数风格

标签:php

匿名函数

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

类静态方法

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

函数

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

对象方法

class A
{
    function test($req, $resp)
    {
        echo "hello world";
    }
}

$object = new A();
$server->on('Request', array($object, 'test'));

原创文章,转载请注明出处!
本文链接:https://wanghongjun2014.github.io/posts/php-four-callback.html
上篇: php快速查看扩展的信息
下篇: centos6.5安装mysql5.6/5.7

请修改_includes/comment.html添加评论代码。