search
Homephp教程PHP开发Excerpted from the PHP manual [4] – Function Handling Functions

Introduction: Function Handling Functions in PHP. Below I will only give a detailed explanation of a few commonly used functions.

call_user_func — Call an existing function
call_user_func_array — Call a function and pass parameters in the form of an array




//The above two functions are relatively similar, but the way of passing in parameters is different.
function phpha_com($a, $b){
echo $a + $b;
}
call_user_func('phpha_com', 1, 2); // 3
call_user_func_array('phpha_com', array(1, 2)) ; // 3
//In addition, if the method in the class is called, it will be in array form:
//Tianya PHP blog http://blog.phpha.com
class phpha{
public function phpha_com($a, $b) {
echo $a + $b;
}
}
call_user_func(array('phpha', 'phpha_com'), 1, 2); // 3
call_user_func_array(array('phpha', 'phpha_com'), array (1, 2)); // 3


create_function — Create an anonymous function
func_get_arg — Get the value of a parameter in the function
func_get_args — Get all the parameters of the function and form an array
func_num_args — Get the value of a function Number of parameters

function_exists — Determine whether a function exists




// phpha_func.php
function phpha($a, $b){
echo $a + $b;
}
? >
// test.php
if( ! function_exists('phpha')){
include 'phpha_func.php';
}
phpha(1, 2); // 3
?>


get_defined_functions — Get all PHP functions and custom functions




var_dump(get_defined_functions());
?>


register_shutdown_function — register a page download The function to be run after the entry is completed
register_shutdown_function The execution mechanism is: PHP transfers the function to be called into memory. This function is called when all PHP statements on the page have been executed. Note that at this time, it is called from memory, not from the PHP page, so the above example cannot use relative paths because PHP has already assumed that the original page does not exist. There is no relative path at all.
Note: register_shutdown_function means calling the function after all PHP statements have been executed. Do not understand it as calling the function when the client closes the streaming browser page.
Tianya PHP Blog http://blog.phpha.com
You can understand the calling conditions like this:
1. When the page is forced to stop by the user
2. When the program code runs out of time
3. When the PHP code execution is completed
【 Tianya Note] can be used to do PHP scheduled tasks. Of course, the better way is to leave it to the Linux server, but users who do not have server permissions because they use virtual hosts can try it.

register_tick_function — Register a function that is called on request
unregister_tick_function — Cancel a function that is called on request

The above is excerpted from the PHP manual [4] – Function Handling Functions. For more related content, please pay attention to the PHP Chinese website (www. php.cn)!


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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment