我有奇怪的问题。这只是类的构造方法,不值得展示其他代码,反正看这段代码:
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)
;
我需要帮助和澄清:)