php深入学习笔记二( 函数内置函数 )

WBOY
Release: 2016-06-23 13:34:27
Original
738 people have browsed it

1. call_?user_?func_?array

调用用户自定义函数,第一个参数是函数名,
第二个参数是函数的参数 必须是是一索引数组

function foobar($arg, $arg2) {    echo __FUNCTION__, " got $arg and $arg2\n";}class foo {    function bar($arg, $arg2) {        echo __METHOD__, " got $arg and $arg2\n";    }}// 普通函数调用call_user_func_array("foobar", array("one", "two"));// 类成员函数调用$foo = new foo;call_user_func_array(array($foo, "bar"), array("three", "four"));
Copy after login




2. call_?user_?func

调用函数 参数不能传递引用 参数
call_user_func(函数名,参数1,参数2...)
call_user_func(function($arg) { print "[$arg]\n"; }, 'test');
Copy after login



3. create_?function 

创建一个匿名函数
$myfunc = create_?function('函数参数','函数体');
$myfunc(函数参数);

$newfunc = create_function('$a,$b', 'return "ln($a) + ln($b) = " . log($a * $b);');echo "New anonymous function: $newfunc\n";echo $newfunc(2, M_E) . "\n";
Copy after login



4. forward_?static_?call_?array

调用一个静态函数 方式同 call_user_func_array


5. forward_?static_?call

调用一个静态函数 方式同 call_user_func


6. func_?get_?arg(index) 

 返回参数列表的某一项 参数为索引值


7. func_?get_?args 

 以数组形式收集所有参数
<?phpfunction sum() {    $acc = 0;    foreach (func_get_args() as $n) {        $acc += $n;    }    return $acc;}echo sum(1, 2, 3, 4);?>
Copy after login




8. func_?num_?args() 

 返回函数传递参数的个数

9. function_?exists  

检测函数是否存在

function_?exists("函数名"); // 检测一个函数是否存在 


10. get_?defined_?functions 

以二维数组形式返回所有定义过的函数
包括系统函数    (internal)
和用户自定义函数(user)
Array(    [internal] => Array        (            [0] => zend_version            [1] => func_num_args            [2] => func_get_arg            [3] => func_get_args            [4] => strlen            [5] => strcmp            [6] => strncmp            ...            [750] => bcscale            [751] => bccomp        )    [user] => Array        (            [0] => myrow        ))
Copy after login



11. register_?shutdown_?function

 该函数注册的函数 ,在系统执行超过最大时间Fatal error时
 仍会执行 注册的函数 
 function add(){    code here... } register_?shutdown_?function("add");
Copy after login


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