zoukankan      html  css  js  c++  java
  • php 全局变量问题

    当在函数里通过require_once包含另外php文件。

    而另外php文件包含了另外php文件,而该php文件的函数需要另外的php文件。

    例子: 

    installment_maintenance_submit.php文件里downloadZip函数在内部包含了rebootTipsFunc.php

    function  downloadZip(){
        
        require_once realpath(dirname(__FILE__)."/lib/rebootTipsFunc.php");
        $downloadUrl = getWebUrlInfo("download_zutai_url");
    
    }

    rebootTipsFunc.php文件

    require_once realpath(dirname(__FILE__)."/../include/global_config.php");
    require_once realpath(dirname(__FILE__)."/../include/web_auth_paramsdesc.php");
    require_once realpath(dirname(__FILE__)."/../include/default_web_config.php");
    require_once realpath(dirname(__FILE__)."/../include/global_feature_config.php");
    
    
    function getWebUrlInfo($key){
    
      // echo $key;
    
       global $g_cfgWebArr;
       // print_r($g_cfgWebArr);
       // global $g_web_paramsdesc;
       global $g_default_cfgWebArr;
      // print_r($g_default_cfgWebArr);
      if(array_key_exists($key,$g_cfgWebArr)){
          return $g_cfgWebArr[$key];
      }else{
           return $g_default_cfgWebArr[$key];
      }
    }

    函数 getWebUrlInfo 里调用了global_config.php文件里的数组$g_cfgWebArr,在函数里用global里用全局变量指定。

    用上述方法指定后,会出现在函数里getWebUrlInfo的$g_cfgWebArr变量无法被识别的情况。

    将installment_maintenance_submit.php里require_once放在函数外部时,则可以正常使用。变量$g_cfgWebArr也可以正常使用

     require_once realpath(dirname(__FILE__)."/lib/rebootTipsFunc.php");
    function  downloadZip(){
    
        $downloadUrl = getWebUrlInfo("download_zutai_url");
    
    }
  • 相关阅读:
    再说ASP.NET 缓存
    asp.net 动态加载的用户控件属性传id值问题
    关于四季学期数据库设计问题
    如何在IIS里对网站限速
    命名空间与程序集
    多GridView页面中使用AJAX的优化方法
    OutputCache cookies 问题
    速度优化之GZIP对jscss压缩
    canphp框架论坛成立www.canphp.com/bbs/index.php现在论坛内测中
    js selection对象使用方法
  • 原文地址:https://www.cnblogs.com/hzijone/p/6297787.html
Copyright © 2011-2022 走看看