From PHP Manual [4]-FunctionHandlingFunctions

Source: Internet
Author: User
Introduction: functions for processing functions in PHP (FunctionHandlingFunctions). below I will only detail several commonly used functions.

Introduction: Function Handling Functions in PHP. below I will only detail several commonly used Functions.

Call_user_func-call an existing function
Call_user_func_array-call a function and pass parameters in array form

 
 
  1. // The two functions are similar, but the input parameters are different.
  2. Function phpha_com ($ a, $ B ){
  3. Echo $ a + $ B;
  4. }
  5. Call_user_func ('phpha _ com', 1, 2); // 3
  6. Call_user_func_array ('phpha _ com', array (1, 2); // 3
  7. // If you call a method in the class, the method is in the array format:
  8. // Tianya PHP blog http://blog.phpha.com
  9. Class phpha {
  10. Public function phpha_com ($ a, $ B ){
  11. Echo $ a + $ B;
  12. }
  13. }
  14. Call_user_func (array ('phpha ', 'phpha _ com'), 1, 2); // 3
  15. 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 number of parameters of a function

Function_exists-determine whether a function exists

 
 
  1. // phpha_func.php
  2. function phpha($a, $b){
  3. echo $a + $b;
  4. }
  5. ?>
  6. // test.php
  7. if( ! function_exists('phpha')){
  8. include 'phpha_func.php';
  9. }
  10. phpha(1, 2); // 3
  11. ?>

Get_defined_functions-obtains all PHP and custom functions.

 
 
  1. var_dump(get_defined_functions());
  2. ?>

Register_shutdown_function-registers a function that runs after a page is loaded.
Register_shutdown_function execution mechanism is: PHP calls the function to the memory. Call this function when all PHP statements on the page are executed. Note: At this time, it is called from the memory instead of from the PHP page. Therefore, the relative path cannot be used in the above example, because PHP already does not exist. There is no relative path.
Note: register_shutdown_function is used to call a function after all PHP statements are executed. do not call the function when the client closes the browser page.
Tianya PHP blog http://blog.phpha.com
The call conditions can be understood as follows:
1. when the page is forcibly stopped by the user
2. when the program code runs out of time
3. When PHP code execution is complete
[Tianya note] it can be used to schedule PHP tasks. of course, it is better to hand over the tasks to the linux server for processing. However, users who do not have the server permission to use the virtual host can try it.

Register_tick_function-registers a function called as required
Unregister_tick_function-cancels a function called as required

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.