PHP function processing function instance details

Source: Internet
Author: User
Explanation of PHP Function handler instance 1. call_user_func and call_user_func_array:

The preceding two functions call the callback function in different parameters. See the following example:

    

The running result is as follows:

bogon:TestPhp$ php call_user_func_test.php This is Test2::printSelf.This is Test2::doSomething.This is Test2::doSomethingWithArgs with ($arg1 = hello and $arg2 = world).This is Test2::doSomethingWithArgs with ($arg1 = hello2 and $arg2 = world2).

2. func_get_args, func_num_args, and func_get_args:

The common features of these three functions are related to user-defined function parameters and can only be used within the function. they are suitable for user-defined functions with variable parameters. Their function prototypes and descriptions are as follows:
Int func_num_args (void) to obtain the number of parameters of the current function.
Array func_get_args (void) returns all parameters of the current function in the form of an array.
Mixed func_get_arg (int $ arg_num) returns the parameter at the specified position of the current function. 0 indicates the first parameter.

   $arg) {        print "$arg\n";    }}myTest('hello','world','123456');

The running result is as follows:

Stephens-Air:TestPhp$ php class_exist_test.php The number of args in myTest is 3The 0th arg is helloThe 1th arg is worldThe 2th arg is 123456-------------------------------------------helloworld123456

3. function_exists and register_shutdown_function:

The function prototype and brief description are as follows:

Bool function_exists (string $ function_name) determines whether a function exists.
Void register_shutdown_function (callable $ callback [, mixed $ parameter [, mixed $...]) call the function to change registration before the script ends or when exit is called midway through. In addition, if multiple functions are registered, they will be executed in sequence at the time of registration. If an internal callback function calls exit (), the script will immediately exit, the remaining callbacks are not executed.

     

The running result is as follows:

Stephens-Air:TestPhp$ php call_user_func_test.php shutdown function exists now.This test is executed.$arg1 = Hello, $arg2 = World

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.