Home > Article > Backend Development > What functions does PHP support callbacks?
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].
PHP supports callback functions:
1, anonymous function
$server->on('Request', function ($req, $resp) use ($a, $b, $c) { echo "hello world"; });
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'));
3, Function
function my_onRequest($req, $resp) { echo "hello world"; } $server->on('Request', 'my_onRequest');
4. Object method
class A { function test($req, $resp) { echo "hello world"; } } $object = new A(); $server->on('Request', array($object, 'test'));
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!