Class xy {
public $x = 10;
public $y = 10;
public function __construct($x = NULL, $y = NULL) {
if(isset($x) || isset($y)){
$this->x = $x; // assign center coords
$this->y = $y; // assign center coords
}
$this->area = $this->area();
echo $this->x . " " . $this->y . " " . $this->area;
}
}
从现在开始,我认为此代码应该回显$ this-> x和$ this-> y WITHOUT if(isset($x) || isset($y)){
,如果没有使用此代码传入对象:$newObj = new xy;
但事实并非如此。仅当此行看起来像$newObj = new xy(10,10)
;
我需要帮助和澄清:)
答案 0 :(得分:0)
我没有使用php多年,但我认为它应该看起来像$ newObj = new xy();
答案 1 :(得分:0)
change $newObj = xy(10,10); to $newObj = new xy(10,10);