在对象内部调用对象方法的语法
可能是一个愚蠢的问题,但我的 IDE (PHPStorm) 和我有一点分歧......
class Item_Backpack {
public function Empty() {
// dump contents
}
public function insertThing($thing) {
// insert thing into backpack
}
}
class Student {
private $_Backpack; // is a class, can contain other objects
function __construct() {
$this->_Backpack = new Item_Backpack;
}
public function emptyBackpack() {
$this->_Backpack->Empty(); // IDE says method undefined
// and cannot give method/property hints
// for this object :-3
}
}
Item_Backpack
类具有方法 public function Empty()
,其中 . .. 清空背包!
我的语法正确吗?
Probably a stupid question, but my IDE (PHPStorm) and I are having a bit of a disagreement...
class Item_Backpack {
public function Empty() {
// dump contents
}
public function insertThing($thing) {
// insert thing into backpack
}
}
class Student {
private $_Backpack; // is a class, can contain other objects
function __construct() {
$this->_Backpack = new Item_Backpack;
}
public function emptyBackpack() {
$this->_Backpack->Empty(); // IDE says method undefined
// and cannot give method/property hints
// for this object :-3
}
}
The Item_Backpack
class has the method public function Empty()
which ... empties the backpack!
Is my syntax correct here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它有问题,因为 empty() 是 PHP 中的保留函数名称 - 您只需将该函数重命名为其他名称,即。空内容()
It's having problems because empty() is a reserved function name in PHP - you just need to rename the function to something else, ie. emptyContents()