phpstorm代码完成不适用于php方法 [英] Phpstorm code completion not working on php methods
问题描述
由于某种原因,代码完成对于本地php代码(例如bind_param(),prepare()和execute())感到担心.我收到此警告:在类中找不到方法'bind_param'.有什么问题吗?
For some reason code completion is worry on native php code such as bind_param(), prepare() and execute(). I get this warning: method 'bind_param' not found in class. What is the problem?
if ($this->comparePassword ( $password, $confirmPass )) {
// Generating password hash
$password_hash = PassHash::hash ( $password );
// insert query
$stmt = $this->conn->prepare ( "INSERT INTO seeker(first_name, last_name, email, password, parish) values(?, ?, ?, ?, ?)" );
$stmt->bind_param ( "sssss", $fName, $lName, $email, $password_hash, $parish );
$result = $stmt->execute ();
$stmt->close ();
// Check for successful insertion
if ($result) {
// User successfully inserted
return USER_CREATED_SUCCESSFULLY;
} else {
// Failed to create user
return USER_CREATE_FAILED;
}
} else {
return PASSWORDS_DO_NOT_MATCH;
}
} else {
// User with same email already existed in the db
return USER_ALREADY_EXISTED;
}
这是自定义类的代码
class DbConnect {
private $conn;
function __construct() {
}
/**
* Establishing database connection
* @return database connection handler
*/
function connect() {
include_once dirname(__FILE__) . './Config.php';
// Connecting to mysql database
$this->conn = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME); //EDIT TO BE PDO
// Check for database connection error
if (mysqli_connect_errno()) { //EDIT TO BE PDO
echo "Failed to connect to MySQL: " . mysqli_connect_error(); //EDIT TO BE PDO
}
// returning connection resource
return $this->conn;
}
}
推荐答案
显然,在我的DbConnect类中,我的PHPDoc注释指出,实际上我在返回"mysqli"数据类型时,我正在返回数据库".这就是导致错误的原因.解决此问题的简单方法是将PHPDoc批注更改为"mysqli",并且代码补全再次开始起作用.
Apparently in my DbConnect class my PHPDoc comments stated that I was returning 'database' when in fact I was returning a 'mysqli' datatype. This was what was causing the error. The simply fix to this problem was to change be PHPDoc annotation to 'mysqli' and the code completions started to work again.
这篇关于phpstorm代码完成不适用于php方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!