gpt4 book ai didi

PHP - 调用未定义的方法

转载 作者:太空宇宙 更新时间:2023-11-03 11:59:31 24 4
gpt4 key购买 nike

我有一个定义了几个函数的 PHP 类,这个类负责数据库访问:

class database {

function open($params) {
// code here to open the db
}

function close() {
// code here to close the db
}

function count_users() {
// code here counts the number of user records

// Return -1 for testing
return -1;
}

function insert_user($user) {
// code here inserts a user record
}

function select_user($user_id) {
// code here selects a user record
}

}

我有如下定义的访问器类:

require_once("database.php");

class user {

public $user_id;
public $email_address;
// etc, etc

}

class db_user {

static function select_user($user_id) {
$db = new database();
$db->open();

$user = NULL;

$result = $db->select_user($user_id);

// Test the result and decode user record into $user, etc

$db->close();

return $user;
}

static function count_users() {
$db = new database();
$db->open();

$count = $db->count_users();

$db->close();

return $count;
}

}

当我尝试通过 db_user::count_users(); 计算用户数量时出现问题总是失败并出现 Fatal Error: call to undefined method database::count_users

如果我使用 get_class_methods 转储数据库类方法,我可以看到 count_users 函数不在列表中,但我不知道为什么。

我是一个 PHP 新手,所以可能有一些很明显我没有做的事情。我的db_useruser类有许多其他功能可以通过 database 拉回数据。类,所有这些都成功了 - 只有这个功能。

请帮忙!


更新

好的,所以,从数据库类中删除了几个函数并将文件重新上传到实时服务器后,当我转储属于数据库对象的方法时,它似乎以某种方式被“缓存”了,删除的方法仍显示在列表中。

count_users 函数也没有出现在方法列表中,当我检查上传到服务器的文件时,它存在于代码中。

有什么方法可以删除这个缓存吗???

最佳答案

尝试如下:

class user extends database {
//code user class goes here
}

class user extends db_user {
//code user class goes here
}

简单的问题解决了。

关于PHP - 调用未定义的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30235252/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com