我试图在类中的另一个方法中使用一个方法。我在 PHP5 OOP 方面没有太多经验,我四处寻找答案,但找不到任何答案。我正在尝试在同一个类中的 sendRequest() 中使用 getClientInfo()。
class DomainHandler {
public static function getClientInfo($db, $client_id)
{
//Do stuff
}
public static function sendRequest($details)
{
require_once('MySQL.class.php');
$db = new MySQL;
getClientInfo($db, $client);
}
}
它告诉我:
Fatal error: Call to undefined function getClientInfo()
我也试过
parent::getClientInfo($db, $client);
和
$this->getClientInfo($db, $client);
没用。
有什么想法吗?
最佳答案
这是一个静态方法,因此您必须使用 self::getClientInfo
或 DomainHandler::getClientInfo
调用它。
此外:您可能想阅读面向对象编程,因为看起来您还没有理解它的真正含义(它不仅仅是将函数放在类 Foo { 和 } 之间并将 public static 放在它们前面)
关于php - 从同一个 PHP 类中的另一个方法调用一个方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2220809/