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

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"));2. call_user_func调用函数 参数不能传递引用 参数call_user_func(函数名,参数1,参数2…)call_user_func(function($arg) { print "[$arg]\n"; }, 'test');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";4. forward_static_call_array调用一个静态函数 方式同 call_user_func_array5. forward_static_call调用一个静态函数 方式同 call_user_func6. 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);?>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))11. register_shutdown_function该函数注册的函数 ,在系统执行超过最大时间Fatal error时仍会执行 注册的函数 function add(){code here… } register_shutdown_function("add");

可你仍然感谢天地和人世所带来的这些变化和发生。

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

相关文章:

你感兴趣的文章:

标签云: