首页 > 关于 php 引用传值的问题

关于 php 引用传值的问题

前些天看 CI 的源代码看到了一些问题

代码段1:

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

代码段2:

<?php
call_user_func_array(array(&$CI, $method), $params);
// 请问将 CI 实例传入 `call_user_func_array` 有什么意义么?
?>

这两个点查阅了文档 但是似乎 引用传值 这个知识点网上资料少的可怜 所以只能恬不知耻来求教给位大牛了。。。

跪谢


call_user_func_array(array(&$CI, $method), $params);

这一句不是说传入CI,而是调用 $CI 的 $method 方法,并带上 $pararms 参数

举个例子:

$method = 'something';
$params = array('a', 'b', 'c');

就相当于调用

$CI->something('a', 'b', 'c');

http://php.net/manual/zh/function.call-user-func-array.php

【热门文章】
【热门文章】