標籤:errors ams self const php ret bug sage require
1.
class CI_Controller { private static $instance; /** * Constructor */ public function __construct() { self::$instance =& $this; // Assign all the class objects that were instantiated by the // bootstrap file (CodeIgniter.php) to local class variables // so that CI can run as one big super object. foreach (is_loaded() as $var => $class) { $this->$var =& load_class($class); } $this->load =& load_class(‘Loader‘, ‘core‘); $this->load->initialize(); log_message(‘debug‘, "Controller Class Initialized"); } public static function &get_instance() { return self::$instance; }}...public function database($params = ‘‘, $return = FALSE, $active_record = NULL) { // Grab the super object $CI =& get_instance(); // Do we even need to load the database class? if (class_exists(‘CI_DB‘) AND $return == FALSE AND $active_record == NULL AND isset($CI->db) AND is_object($CI->db)) { return FALSE; } require_once(BASEPATH.‘database/DB.php‘); if ($return === TRUE) { return DB($params, $active_record); } // Initialize the db variable. Needed to prevent // reference errors with some configurations $CI->db = ‘‘; // Load the DB class $CI->db =& DB($params, $active_record); }
$a=test()方式調用函數,只是將函數的值賦給$a而已, 而$a做任何改變 都不會影響到函數中的$b
而通過$a=&test()方式調用函數呢, 他的作用是 將return $b中的 $b變數的記憶體位址與$a變數的記憶體位址 指向了同一個地方
即產生了相當於這樣的效果($a=&$b;) 所以改變$a的值 也同時改變了$b的值 所以在執行了
$a=&test();
$a=5;
以後,$b的值變為了5
http://www.cnblogs.com/xiaochaohuashengmi/archive/2011/09/10/2173092.html
第11月第21天 php引用