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

Introduction to several PHP callback functions

小云云
Release: 2023-03-22 13:14:01
Original
1511 people have browsed it

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";
});
Copy after login

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

Function

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

Object method

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

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!

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