Home >Backend Development >PHP Tutorial >Introduction to several PHP callback functions
This article mainly shares with you an introduction to several PHP callback functions, mainly in code, hoping to help everyone.
Anonymous function
$server->on('Request', function ($req, $resp) { echo "hello world"; });
Class static method
class A{ static function test($req, $resp) { echo "hello world"; } }$server->on('Request', 'A::Test');$server->on('Request', array('A', 'Test'));
Function
function my_onRequest($req, $resp) { echo "hello world"; }$server->on('Request', 'my_onRequest');
Object method
class A{ function test($req, $resp) { echo "hello world"; } }$object = new A();$server->on('Request', array($object, 'test'));
Related recommendations:
Detailed explanation of the use of PHP callback functions and anonymous functions
Analysis of PHP callback functions
Concept and usage of PHP callback functions
The above is the detailed content of Introduction to several PHP callback functions. For more information, please follow other related articles on the PHP Chinese website!