在我下载最新的codeigniter框架后,首次运行就出现了如下错误:
![](/attachment/201412/14/29954686_141857098790nb.png)
经过查资料知道,原来是在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) |