Home > php教程 > PHP开发 > Excerpted from the PHP manual [4] – Function Handling Functions

Excerpted from the PHP manual [4] – Function Handling Functions

黄舟
Release: 2016-12-22 10:13:16
Original
1337 people have browsed it

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)!


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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template