Heim  >  Artikel  >  Backend-Entwicklung  >  php深入学习笔记2( 函数内置函数 )

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

WBOY
WBOYOriginal
2016-06-13 12:20:02924Durchsuche

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_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);?>




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");


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn