Php 未定义变量错误

Php 未定义变量错误,php,Php,嗨,我是丹尼斯,我是php新手。我爸爸是一名PHP开发人员,但我想自己做这件事。我现在11岁了!!!:) 我为我的php东西做了一个安装程序,我得到了以下错误: Notice: Undefined variable: config in \path\to\core.php on line 20 失败的是这一部分: $system['home_url'] = "".$config['home']['url'].""; 但是如果我之前包含了配置文件,并且这个变量没有定义,它怎么会失败呢 我做到了

嗨,我是丹尼斯,我是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
的解决方案,但我真的不知道它是如何工作的

再见!!!谢谢:))

编辑-- Core.PHP


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";

?>


使用前检查变量,如
isset($config['home']['url'])
您也可以使用
!空($config['home']['url'])

请在使用前检查变量lik
isset($config['home']['url'])
您也可以使用
!空($config['home']['url'])

它是数组吗?因为你有一个多元素数组,你确定你的脚本文件和config.php在同一个目录下吗?范围问题?请出示您的完整代码(至少相关的代码)。另外:
。$var.
是没有意义的,您将空字符串连接到变量,再连接到空字符串。只要做
$var
。谢谢你的评论,我现在就发布,我会按照你的建议去做。是的,它在同一个目录中。它是数组吗?因为你有一个多元素数组,你确定你的脚本文件和config.php在同一个目录下吗?范围问题?请出示您的完整代码(至少相关的代码)。另外:
。$var.
是没有意义的,您将空字符串连接到变量,再连接到空字符串。只需执行
$var
。感谢您的评论,我现在就发布它,我会遵循您的建议,是的,它位于同一个目录中。我认为正确的解决方案是构造代码,以便可以访问变量。抑制错误不是解决办法,它只是隐藏了试图指出错误的症状!我认为正确的解决方案是构造代码,以便可以访问变量。抑制错误不是解决办法,它只是隐藏了试图指出错误的症状!
<?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";

?>