函数处理
http://php.net/manual/zh/book.funchand.php
php除了按照传统方式进行new ,调用方法之外,还有一些特殊的方式
也许,在现在的我来说,是比较方便,但是,也可能是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')
实际用处有时候是要对一些现有的类做二次封装
例2 register_shutdown_function
http://php.net/manual/zh/function.register-shutdown-function.php
会在_destruct前执行,php进程结束前会执行
至于这么写有什么用,今天看到的例子是在日志类中,输出相应的东西,也可以在最后捕捉异常
但是,要尽量写在前面,否则有可能还没设置register_shutdown_function,就已经被中断了。