【发布时间】:2014-01-05 23:30:07
【问题描述】:
class Item {
public $itemname;
somekeyword $error; //The correct keyword I want to find
public function insertData() {
$query = "INSERT INTO table VALUES ('".$this->itemname."')";
try {
//HERE THERE IS A NICE CODE TO EXECUTE THE QUERY AND SO...
return true; //Returns true on success
} catch(PDOExecption e) {
$this->error = $PDOObject->errorInfo();
return false; //Returns false on FAIL but the Object has a property with the error information
}
}
}
我怎样才能使属性错误只能针对此类方法进行更改?我不希望它在外部被另一个类或文件更改。
关键字“受保护”是否可以使其在外部可读但不可更改?
谢谢!
【问题讨论】:
-
离题,但您的代码可能容易受到 sql 注入的影响。
-
谢谢 Matthew,是的,我只是为示例编写了这样的代码,但在实际代码中,我已经准备好了语句和安全验证!
标签: php class properties