if (! function_exists (' Get_config ')) {/** * Loads the main config.php file * * This function lets us grab The config file even if the Config class * hasn ' t been instantiated yet * * @param array * @return A Rray */function &get_config (array $replace = Array ()) {static $config; if (empty ($config)) {$file _path = APPPATH. ' config/config.php '; $found = FALSE; if (file_exists ($file _path)) {$found = TRUE; Require ($file _path); }//Is the config file in the environment folder? if (file_exists ($file _path = APPPATH. ' config/'). Environment. ' /config.php ') {require ($file _path); } elseif (! $found) {set_status_header (503); Echo ' The configuration file does not exist. '; Exit (3); Exit_config} Does the $config array exist in the file? if (! isset ($config) OR! Is_array ($config)) {Set_status_header (503); echo ' Your config file does not appear to be formatted correctly. '; Exit (3); Exit_config}}//Is any values being dynamically added or replaced? foreach ($replace as $key = = $val) {$config [$key] = $val; } return $config; }}//------------------------------------------------------------------------if (! function_exists (' Config_item ') {/** * Returns the specified config item * * @param string * @return Mixed */function C Onfig_item ($item) {static $_config; if (empty ($_config)) {//references cannot is directly assigned to static variables, so we use an array $_config[0] =& get_config (); } return Isset ($_config[0][$item])? $_config[0][$item]: NULL; }}
$_config[0] =& get_config();
and function &get_config(Array $replace = array())
&
The function of the symbol inside is not quite understood = = &
What is the special function of using the symbol here = = Ask for answer ~
Reply content:
if (! function_exists (' Get_config ')) {/** * Loads the main config.php file * * This function lets us grab The config file even if the Config class * hasn ' t been instantiated yet * * @param array * @return A Rray */function &get_config (array $replace = Array ()) {static $config; if (empty ($config)) {$file _path = APPPATH. ' config/config.php '; $found = FALSE; if (file_exists ($file _path)) {$found = TRUE; Require ($file _path); }//Is the config file in the environment folder? if (file_exists ($file _path = APPPATH. ' config/'). Environment. ' /config.php ') {require ($file _path); } elseif (! $found) {set_status_header (503); Echo ' The configuration file does not exist. '; Exit (3); Exit_config} Does the $config array exist in the file? if (! isset ($config) OR! Is_array ($config)) {Set_status_header (503); echo ' Your config file does not appear to be formatted correctly. '; Exit (3); Exit_config}}//Is any values being dynamically added or replaced? foreach ($replace as $key = = $val) {$config [$key] = $val; } return $config; }}//------------------------------------------------------------------------if (! function_exists (' Config_item ') {/** * Returns the specified config item * * @param string * @return Mixed */function C Onfig_item ($item) {static $_config; if (empty ($_config)) {//references cannot is directly assigned to static variables, so we use an array $_config[0] =& get_config (); } return Isset ($_config[0][$item])? $_config[0][$item]: NULL; }}
$_config[0] =& get_config();
and function &get_config(Array $replace = array())
&
The function of the symbol inside is not quite understood = = &
What is the special function of using the symbol here = = Ask for answer ~
Reference passing and reference return, to some extent, can save memory space, but also can achieve indirect modification of target values.
Reference delivery Official document: http://www.php.net/manual/zh/language.references.pass.php
Reference back to official document: http://php.net/manual/zh/language.references.return.php
Here I return for a function reference, extending an example
function &get_config(){ static $config = 0; $config += 1; echo sprintf("config=%d\n",$config); return $config;}$config_item = get_config();$config_item = 100;$config_item = get_config();$config_item = &get_config(); // 注意这里的&$config_item = 100;$config_item = get_config();//输出config=1config=2config=3config=101
Save memory by passing references.
//它们都指向静态全局变量$config的zval$config1 = &get_config(); $config2 = &get_config();