Home >Backend Development >PHP Tutorial >Introduction to several PHP callback functions

Introduction to several PHP callback functions

小云云
小云云Original
2018-03-27 15:58:451510browse

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!

Statement:
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
Previous article:Very useful PHP functionsNext article:Very useful PHP functions