CodeIgniter in the source code about the Config_item function does not understand the place

Source: Internet
Author: User
Tags codeigniter
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();
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.