我试图为列表对象创建公共实例。但我无法实现。
class DimensionDistribution
{
public $Distributionch;
public $DistributionCount;
}
class DimensionsValue
{
public $DimensionName;
public function __construct()
{
list($Dimensiondistribution)=array(new DimensionDistribution());
}
}
class value extends DimensionsValue
{
$this->$DimensionName; // It works fine
public function __construct()
{
$this->$Dimensiondistribution;
// If I try to call list object in a above method it doesn't show
// list of variables
}
}
我的问题是如何为列表对象创建公共实例? 提前致谢
答案 0 :(得分:1)
我不确定我是否不提出您的问题,但也许这可以帮助您:
class value extends DimensionsValue
{
public function __construct()
{
parent::__construct();
}
}
答案 1 :(得分:0)
你应该这样试试:
class DimensionsValue
{
public $DimensionName;
public function __construct()
{
list($this->DimensionName)=array(new DimensionDistribution());
}
}
而不是:
class value extends DimensionsValue
{
$this->$DimensionName; // It works fine
public function __construct()
{
$back= $this->DimensionName;
}
}
我不确定它是否会起作用,但请试一试。
答案 2 :(得分:0)
试试这个
class DimensionsValue
{
public $DimensionName;
public function __construct()
{
list($Dimensiondistribution)=array(new DimensionDistribution());
}
}
class value extends DimensionsValue
{
$this->$DimensionName; // It works fine
}
$ DimensionsValue = new DimensionsValue();
$ DimensionsValue->Dimensiondistribution;
更新1:尝试一下,希望它能正常工作
class DimensionsValue
{
public $DimensionName;
public function newData()
{
list($DimensionVar)=array(new DimensionDistribution());
echo $DimensionVar->Distributionch;
return $DimensionVar;
}
}
class verify
{
function __construct()
{
$dm=new DimensionsValue();
$same=$dm->newData();
$same->Distributionch;
$same->DistributionCount;
}
}