php的類中可以不定義成員變量,直接在構造方法中使用并賦值嗎?class block {
function block()
{
$this->iconWidth = "23";
$this->iconHeight = "23";
$this->bgColor = "#5B7F93";
$this->fgColor = "#C4D3DB";
$this->oddColor = "#F5F5F5";
$this->evenColor = "#EFEFEF";
$this->highlightOn = "#DEE7EB"; $this->class = "odd";
$this->highlightOff = $this->oddColor;
$this->theme = THEME;
$this->pathImg = "../themes";
}
...
}
這是我看到的一個類,感覺很奇怪,它也沒有父類。
function block()
{
$this->iconWidth = "23";
$this->iconHeight = "23";
$this->bgColor = "#5B7F93";
$this->fgColor = "#C4D3DB";
$this->oddColor = "#F5F5F5";
$this->evenColor = "#EFEFEF";
$this->highlightOn = "#DEE7EB"; $this->class = "odd";
$this->highlightOff = $this->oddColor;
$this->theme = THEME;
$this->pathImg = "../themes";
}
...
}
這是我看到的一個類,感覺很奇怪,它也沒有父類。
php 的变量不也都是不经声明就可使用的吗?
{
function testgo()
{
$this -> base = 'ok';
}
function echos()
{
echo $this -> base;
}
}$t = new tests();
$t -> testgo();
$t -> echos();
可以的。但最好定义先吧。可定公共或私有....==这样明了些。