php深入學習筆記二( 函數內建函數 )

來源:互聯網
上載者:User

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

以數組形式收集所有參數





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");
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.