Chinaunix首页 | 论坛 | 博客
  • 博客访问: 97763
  • 博文数量: 21
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2014-10-11 22:44
个人简介

HUST16届准毕业生,发奋求职中...

文章分类

全部博文(21)

文章存档

2015年(17)

2014年(4)

我的朋友

分类: PHP

2014-12-15 00:57:59

    在我下载最新的codeigniter框架后,首次运行就出现了如下错误:

经过查资料知道,原来是在php5向后兼容不是很理想,当一个函数出现多个return语句时,就会出现这样的报错。
以下是框架原来的写法:
if ( ! function_exists('get_config'))
{
function &get_config($replace = array())
{
static $_config;


if (isset($_config))
{
return $_config[0];
}


// Is the config file in the environment folder?
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
$file_path = APPPATH.'config/config.php';
}


// Fetch the config file
if ( ! file_exists($file_path))
{
exit('The configuration file does not exist.');
}


require($file_path);


// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
exit('Your config file does not appear to be formatted correctly.');
}


// Are any values being dynamically replaced?
if (count($replace) > 0)
{
foreach ($replace as $key => $val)
{
if (isset($config[$key]))
{
$config[$key] = $val;
}
}
}


return $_config[0] =& $config;
}
}

通过增加一个$result中间变量,减少了return语句,终于恢复正常,代码如下:
if ( ! function_exists('get_config'))
{
function &get_config($replace = array())
{
static $_config;


if (isset($_config))
{
$result=$_config[0];
}


// Is the config file in the environment folder?
if ( ! defined('ENVIRONMENT') OR ! file_exists($file_path = APPPATH.'config/'.ENVIRONMENT.'/config.php'))
{
$file_path = APPPATH.'config/config.php';
}


// Fetch the config file
if ( ! file_exists($file_path))
{
exit('The configuration file does not exist.');
}


require($file_path);


// Does the $config array exist in the file?
if ( ! isset($config) OR ! is_array($config))
{
exit('Your config file does not appear to be formatted correctly.');
}


// Are any values being dynamically replaced?
if (count($replace) > 0)
{
foreach ($replace as $key => $val)
{
if (isset($config[$key]))
{
$config[$key] = $val;
}
}
}
if(!isset($result))
$result=& $config;
return $result;
}
}


阅读(1978) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:CentOS安装crontab及使用方法(转)

给主人留下些什么吧!~~