前些天看 CI 的源代码看到了一些问题
代码段1:
<code><?phpstatic $_log;if ($_log === null) { // references cannot be directly assigned to static variables, so we use an array // 为什么要这样?源代码中写了注释但是跟没写一样。。。 $_log[0] =& load_class('Log', 'core');}$_log[0]->write_log($level, $message);?></code>
代码段2:
<code><?phpcall_user_func_array(array(&$CI, $method), $params);// 请问将 CI 实例传入 `call_user_func_array` 有什么意义么??></code>
这两个点查阅了文档 但是似乎 引用传值 这个知识点网上资料少的可怜 所以只能恬不知耻来求教给位大牛了。。。
跪谢
回复内容:
前些天看 CI 的源代码看到了一些问题
代码段1:
<code><?phpstatic $_log;if ($_log === null) { // references cannot be directly assigned to static variables, so we use an array // 为什么要这样?源代码中写了注释但是跟没写一样。。。 $_log[0] =& load_class('Log', 'core');}$_log[0]->write_log($level, $message);?></code>
代码段2:
<code><?phpcall_user_func_array(array(&$CI, $method), $params);// 请问将 CI 实例传入 `call_user_func_array` 有什么意义么??></code>
这两个点查阅了文档 但是似乎 引用传值 这个知识点网上资料少的可怜 所以只能恬不知耻来求教给位大牛了。。。
跪谢
<code>call_user_func_array(array(&$CI, $method), $params);</code>
这一句不是说传入CI,而是调用 $CI 的 $method 方法,并带上 $pararms 参数
举个例子:
<code>$method = 'something'<mark>@本文来源gaodaimacom搞#代%码@网-</mark><strong>搞代gaodaima码</strong>;$params = array('a', 'b', 'c');</code>
就相当于调用
<code>$CI->something('a', 'b', 'c');</code>
http://php.net/manual/zh/function.call-user-func-array.php