我是php的初学者,以前使用过Java。 这是我的php类代码:
class Set
{
private $_set;
public function __construct(){
$_set = array();
}
public function add($val){
print($_set);
}
}
它告诉我未定义变量$ _set 在添加函数中。但是变量 $ _ set 已经作为字段变量存在。所以,我不知道为什么我不能在add函数中访问字段变量。
答案 0 :(得分:1)
class Set
{
private $_set;
public function __construct(){
this->_set = array();
}
public function add($val){
print($this->_set);
}
}
您必须使用$this->
来解决类的属性。