在课堂上找不到方法 [英] Method not found in class
本文介绍了在课堂上找不到方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用登录功能,但是遇到了我无法弄清的错误.
I'm working on a login function but got an error that I can't figure out.
这是我的模型登录课程:
This is my Model Login class:
class Login {
private $username;
private $password;
private $cxn; //database object
function __construct($username,$password)
{
//set data
$this->setData($username, $password);
//connect DB
$this->connectToDB();
// get Data
}
function setData($username, $password)
{
$this->username = $username;
$this->password = $password;
}
private function connectToDB()
{
include 'Database.php';
$connect = '../include/connect.php';
$this->cxn = new database($connect);
}
function getData()
{
$query = "SELECT * FROM anvandare WHERE anvandarnamn = '$this->username' AND losenord ='$this->'password'";
$sql = mysql_query($query);
if(mysql_num_rows($sql)>0)
{
return true;
}
else
{
throw new Exception("Användarnamnet eller Lösenordet är fel. Försök igen.");
}
}
function close()
{
$this->cxn->close(); //Here is the error it says "Method 'close' not found in class
}
}
最后一个函数给出错误"在类中未找到方法'close'","在主题类中未找到引用的方法."
The last function gives error "Method 'close' not found in class", "Referenced method is not found in subject class."
这是我的数据库课程:
class Database {
private $host;
private $user;
private $password;
private $database;
function __construct($filename)
{
if(is_file($filename)) include $filename;
else throw new exception("Error!");
$this->host=$host;
$this->user=$user;
$this->password=$password;
$this->database=$database;
$this->connect();
}
private function connect()
{
//Connect to the server
if(!mysql_connect($this->host, $this->user, $this->password))
throw new exception("Error, not connected to the server.");
//Select the database
if(!mysql_select_db($this->database))
throw new exception("Error, no database selected");
}
function close()
{
mysql_close();
}
}
路径是正确的,事实并非如此.可能是什么错误?
The pathways are correct so it's not it. What could be the error?
推荐答案
PhpStorm无法确定您的$this->cxn
字段是什么类型.您可以通过简单的PHPDoc注释提供typehint来提供帮助:
PhpStorm cannot figure out what type your $this->cxn
field is. You can help by providing typehint via simple PHPDoc comment:
/** @var Database */
private $cxn; //database object
这篇关于在课堂上找不到方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文