Rarely used but powerful functions in PHP_PHP Tutorial

WBOY
Release: 2016-07-21 14:56:07
Original
790 people have browsed it

call_user_func_array — Call a function with parameters in the form of an array
call_user_func — Call an existing function
create_function — Create a 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
get_defined_functions — Get existing function information
register_shutdown_function — Register a page load Enter a function that runs after completion
register_tick_function — register a function that is called on request
unregister_tick_function — cancel a function that is called on request

get_defined_functions can get all PHP functions and custom functions:

function a(){}
$b = get_defined_functions();
print_r($b);
//may display more than 1000 defined function:)
?>
The function_exists function determines whether a function exists (it can be a PHP function or a custom function).

if (function_exists('a')) {
echo "yes";
} else {
echo "no";
}
function a(){}
// Display yes
?>
The call_user_func function is similar to a special method of calling a function. The method of use is as follows:

function a($b,$c)
{
echo $b;
echo $c;
}
call_user_func('a', "111","222 ");
call_user_func('a', "333","444");
//Display 111 222 333 444
?>
It is strange to call the method inside the class, actually using is an array, I don’t know how the developers thought about it. Of course, new is omitted, which is also full of novelty:

class a {
function b($c)
{
echo $c;
}
}
call_user_func(array("a", "b"),"111");
//Display 111
?>
The call_user_func_array function is very similar to call_user_func, except that the parameters are passed in a different way to make the structure of the parameters clearer:

function a($b , $c)
{
echo $b;
echo $c;
}
call_user_func_array('a', array("111", "222"));
//Display 111 222
?>
Both the call_user_func function and the call_user_func_array function support references, which makes them more functionally consistent with ordinary function calls:

function a(&$b)
{
$b++;
}
$c = 0;
call_user_func('a', &$c);
echo $c; //Display 1
call_user_func_array('a', array(&$c));
echo $c;//Display 2
?>
func_num_args function can get the parameters accepted by the function Quantity:

function a()
{
echo func_num_args();
}
a(111, 222, 333);
//Display 3
?>
The func_get_arg function can get the value of a passed parameter. In the following example, the function does not specify which parameters will be accepted. You can also get it by using func_get_arg Additional parameters:

function a()
{
echo func_get_arg(1);
}
a (111, 222, 333);
//Display 222
?>

  • Total 2 pages:
  • Previous page
  • 1
  • 2
  • Next page

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/364290.htmlTechArticlecall_user_func_array Let the parameters be in the form of an array to call a function call_user_func Call an existing function create_function Create a function func_get_arg Get the function A certain parameter...
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