时,我有2班(2个文件)问题延伸的PHP类
db.class.php
user.class.php
我想使用一些功能从db.class.php
:
db.class.php
Class DBManager {
/** all functions goes here ...*/
}
$DB = new DBManager();
user.class.php的内容是:
Class User extends DBManager {
function User() {
}
function Total($table) {
$query = $DB->Execute("SELECT * FROM $table");
$total = $DB->NumRows($query);
return $total;
}
}
$User = new User();
当我想用我的新功能合计($表)我得到2个错误:
Undefined variable: DB in ..\class\user.class.php on line 14
Fatal error: Call to a member function Execute() on a non-object in ..\class\user.class.php on line 14
我包括2类像我的main.php文件:
include 'class/db.class.php'; include 'class/user.class.php';
编辑1:
相关岗位:best trick when using an extending class (PHP)
*(参考)* [类和对象 - 基础知识(http://de2.php.net/manual/en/language.oop5.basic。 php) – Gordon 2011-01-29 10:49:41
你为什么不使用PHP5语法的任何原因?如果你在那里学习一个教程,你应该得到一个更新的教程。 – Gordon 2011-01-29 10:51:47
@戈登:我已经有我的课了。我在这里有一个问题。这是什么参考? – Cheerio 2011-01-29 10:52:17