【发布时间】:2011-05-09 17:50:58
【问题描述】:
使用这个函数我想创建一个 PHP 导航:
function loadPage($pagename) {
if (!isset($pagename) || !file_exists($pagename . '.php')) {
include FRONTPAGE . '.php';
} else {
include $pagename . '.php';
}
}
在我的索引中,我有以下内容:
require 'includes/classes/core.php';
$core = new SH_Core();
我可以从 $core 访问所有其他类,例如 $core->database->newConnection(); 而且我应该也可以在包含的文件中使用它。但我不能:
Notice: Undefined variable: core in C:\Users\Development\Development applications\localhost\htdocs\Shuze\frontpage.php on line 4
Notice: Trying to get property of non-object in C:\Users\Development\Development applications\localhost\htdocs\Shuze\frontpage.php on line 4
Fatal error: Call to a member function newConnection() on a non-object in C:\Users\Development\Development applications\localhost\htdocs\Shuze\frontpage.php on line 4
【问题讨论】: