2012-12-09 44 views
1

嗨,我是丹尼斯,我是新来的PHP。我的父亲是一名PHP开发人员,但我想自己做。我现在11岁了! :)未定义变量错误

我做了一个安装程序为我的PHP的事情,我得到这个错误:

Notice: Undefined variable: config in \path\to\core.php on line 20 

这是这部分是失败的:

$system['home_url'] = "".$config['home']['url'].""; 

但如何,如果我包括失败配置文件之前,这个变量不是未定义的!

我所做的:require('config.php');

config.php文件代码:

$config['home']['url'] = "http://localhost/"; 

我使用的变量,对不对?我搜索了所有的互联网,我只找到解决方案,使用global,但我真的不知道它是如何工作的。

再见!!!使用前LIK isset($config['home']['url'])和感谢:)))

EDIT-- core.php中

<?PHP 
/*======================================================================= 
| ####################################################################### 
| This program is free software: you can redistribute it and/or modify 
| it under the terms of the GNU General Public License as published by 
| the Free Software Foundation, either version 3 of the License, or 
| (at your option) any later version. 
| ####################################################################### 
| This program is distributed in the hope that it will be useful, 
| but WITHOUT ANY WARRANTY; without even the implied warranty of 
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
| GNU General Public License for more details. 
\======================================================================*/ 
require('config.php'); 

$system['home_url'] = "".$config['home']['url'].""; 
$system['updates_enabled'] = "".$config['updates']['enabled'].""; 
$system['update_url'] = "".$config['update']['url'].""; 
$system['language'] = $config['language']; 
$system['favicon'] = "".$config['favicon'].""; 
$system['maintenance_status'] = "".$config['maintenance']['status'].""; 
$system['version'] = "".$config['version'].""; 
$system['master_user'] = "".$config['master']['user'].""; 
$system['master_password'] = "".$config['master']['password'].""; 
$system['config_path'] = "config.php"; 

/*====================================================================*/ 

$site['name'] = "".$config['site']['name'].""; 
$site['desc'] = "".$config['site']['desc'].""; 

/*====================================================================*/ 

$cloud_panel['reload_time'] = "".$config['reload']['time'].""; 

/*====================================================================*/ 

require "".$system['home_url']."lang/lang_".$system['language'].".php"; 

/*====================================================================*/ 

$template['id'] = "".$config['template']['id'].""; 
$template['webgallery_type'] = "".$config['webgallery']['type'].""; 
$template['webgallery_url'] = "".$config['webgallery']['url'].""; 

/*====================================================================*/ 

if(isset($_GET['help'])) { header('Location: '.$system['home_url'].'help.php'); } 

/*====================================================================*/ 

if ($template['webgallery_type'] == 1) { $template['my_webgallery'] = "".$system['home_url']."cdn/web-gallery"; } else { $template['my_webgallery'] = $template['webgallery_url']; } 

/*====================================================================*/ 

?> 

的config.php

<?PHP 
/*======================================================================= 
| ####################################################################### 
| This program is free software: you can redistribute it and/or modify 
| it under the terms of the GNU General Public License as published by 
| the Free Software Foundation, either version 3 of the License, or 
| (at your option) any later version. 
| ####################################################################### 
| This program is distributed in the hope that it will be useful, 
| but WITHOUT ANY WARRANTY; without even the implied warranty of 
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
| GNU General Public License for more details. 
\======================================================================*/ 

$config['site']['name'] = "heya"; 
$config['site']['desc'] = "heya"; 
$config['home']['url'] = "http://localhost/"; 
$config['updates']['enabled'] = "1"; 
$config['update']['url'] = "http://localhost/update"; 
$config['language'] = "es"; 
$config['favicon'] = "favicon.ico"; 
$config['maintenance']['status'] = "1"; 
$config['reload']['time'] = "10"; 
$config['version'] = "1.3.4"; 
$config['master']['user'] = "heya"; 
$config['master']['password'] = "heya"; 
$config['template']['id'] = "9"; 
$config['webgallery']['type'] = "1"; 
$config['webgallery']['url'] = "heya"; 

?> 
+0

是数组?因为你在这里有一个多维数组 –

+0

你确定你的脚本文件与config.php在同一目录吗? – SaidbakR

+0

范围界定问题?请显示您的完整代码(至少相关至少)。另外:'“”。$ var。“”'是毫无意义的,你将一个空字符串与一个变量连接成一个空字符串。只要做'$ var'。 – deceze

回答

2

检查参数,你也可以使用!empty($config['home']['url'])

+0

我认为正确的解决方案是构造代码,使变量是可访问的。抑制错误不是解决方案,它只是隐藏了试图指出错误的症状! – deceze