可能是一个愚蠢的问题,但我的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()
,它…清空背包!
这里的语法正确吗?
它有问题,因为empty()是PHP中保留的函数名-你只需要将函数重命名为其他东西,即。emptyContents ()