你好傢伙我想在這裏一些幫助在父類中調用如何變量
我有這個類:
class product
{
var $title;
var $price;
function __construct($title1,$price1)
{
$this->title=$title1;
$this->price=$price1;
}
function set_title($newtitle){
$this->title=$newtitle;
}
function get_title() {
return $this->title;
}
function set_price($newprice)
{
return $this->price=$newprice;
}
function getProductAtrribute()
{
$x1=$this->title;
$x2=$this->price;
$x3=$this->**material**;
$x4=$this->**size1**;
return $allattribute= array("$x1","$x2","x3","x4");
}
}
和其他班組長:
class furinture extends product
{
var $size;
var $material;
function __construct($sizeset,$materialset)
{
parent::__construct();
$this->size=$sizeset;
$this->material=$materialset;
}
function setsize ($size1,$material1)
{
$this->size=$size1;
$this->material=$material1;
}
我試圖做我設置的大小和材料的類傢俱的價值,但從功能得到所有屬性在類產品我試圖使全局變量,但它不會工作。
注意:$ size和$ material我希望他們定義類似於其定義的傢俱類
http://stackoverflow.com/questions/6456939/php-accessing-parent-class-variable –
這如何訪問父類中我需要訪問子類 –
http://stackoverflow.com/questions/13774612/access-child-class-static-variables-from-parent-class –