What functions does PHP support callbacks?

coldplay.xixi
Release: 2023-03-01 19:26:01
Original
2709 people have browsed it

PHP supports callback functions: 1. Anonymous function, code is [$server->on 'Request']; 2. Class static method, code is [static function test $req]; 3. Function, code is [my_onRequest $req].

What functions does PHP support callbacks?

PHP supports callback functions:

1, anonymous function

$server->on('Request', function ($req, $resp) use ($a, $b, $c) {
    echo "hello world";
});
Copy after login

You can use use to pass parameters to anonymous functions

2, Class static method

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

3, Function

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

4. Object method

class A
{
    function test($req, $resp)
    {
        echo "hello world";
    }
}
$object = new A();
$server->on('Request', array($object, 'test'));
Copy after login

Related learning recommendations: PHP programming from entry to proficiency

The above is the detailed content of What functions does PHP support callbacks?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template