Load the configuration function load_config in PHPCMS

Source: Internet
Author: User
Is the isset in the code {code...} always false? Because the array $ configs at the beginning is empty. The main reason is not to understand static $ configsarray (); after $ configs, isn't it an empty array. Sorry, don't step on me any more.
public static function load_config($file, $key = '', $default = '', $reload = false) {    static $configs = array();    if (!$reload && isset($configs[$file])) {        if (empty($key)) {            return $configs[$file];        } elseif (isset($configs[$file][$key])) {            return $configs[$file][$key];        } else {            return $default;        }    }

Is isset always false in this code? Because the array $ configs at the beginning is empty. The main reason is not to understand static $ configs = array (); after $ configs, isn't it an empty array. Sorry, don't step on me any more.

Reply content:
public static function load_config($file, $key = '', $default = '', $reload = false) {    static $configs = array();    if (!$reload && isset($configs[$file])) {        if (empty($key)) {            return $configs[$file];        } elseif (isset($configs[$file][$key])) {            return $configs[$file][$key];        } else {            return $default;        }    }

Is isset always false in this code? Because the array $ configs at the beginning is empty. The main reason is not to understand static $ configs = array (); after $ configs, isn't it an empty array. Sorry, don't step on me any more.

Local static variables retain the value of the previous execution and will not be reinitialized. Your code is not fully intercepted. The $ configs value assignment statement follows. you can simply addprint_f($configs);Let's take a look at the $ configs value every time load_config is called.

The purpose of this operation is to cache the $ configs value during the current execution process to avoid the judgment and include operations of the file_exists consumed in the future.

For details, see TIPI: static variables.

static $configs = array();

Static variables

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.