函數(shù)處理
http://php.net/manual/zh/book.funchand.php
php除了按照傳統(tǒng)方式進行new ,調(diào)用方法之外,還有一些特殊的方式
也許,在現(xiàn)在的我來說,是比較方便,但是,也可能是php被人詬病的拐彎多的地方
例1 call_user_func_array
http://php.net/manual/zh/function.call-user-func-array.php
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 the foobar() function with 2 arguments
call_user_func_array("foobar", array("one", "two"));
// Call the $foo->bar() method with 2 arguments
$foo = new foo;
call_user_func_array(array($foo, "bar"), array("three", "four")); # 這里就相當于$foo0>bar('three','four')
實際用處有時候是要對一些現(xiàn)有的類做二次封裝
例2 register_shutdown_function
http://php.net/manual/zh/function.register-shutdown-function.php
會在_destruct前執(zhí)行,php進程結(jié)束前會執(zhí)行
至于這么寫有什么用,今天看到的例子是在日志類中,輸出相應(yīng)的東西,也可以在最后捕捉異常
但是,要盡量寫在前面,否則有可能還沒設(shè)置register_shutdown_function,就已經(jīng)被中斷了。