这是我创建数据元素列表的代码!在下面提到的这行中有两个错误(在同一行)
1)注意:未定义的偏移量:0 2)致命错误:在非对象上调用成员函数 display()
<?php
class data
{
public $num;
public $Char;
function __construct()
{
$this->num= "null";
$this->Char= "New Char";
}
public function setInt($int)
{
$this->num=$int;
}
public function setChar($char)
{
$this->Char= $char;
}
public function getInt()
{
return $this->num;
}
public function getChar()
{
return $this->Char;
}
public function display()
{
echo $this->num;
echo $this->Char;
}
}
class linklist extends data
{
public $DATA;
private $list;
private $count;
function __construct()
{
$DATA= new data();
$list= array();
$count=0;
}
function addData(data $d)
{
$this->list[$this->count]= $d;
$this-> count++;
}
function displayy()
{
$d= new data();
$i=0;
for($i;$i<=$this->count; $i++)
{
$this->list[$i]->display(); //** line with error *** //
}
}
}
?>
<!DOCTYPE html>
<html>
<body>
<?php
$d= new data();
//$d->display();
//$Name= $_POST['fname'];
//$Age = $_POST['age'];
$d->setInt("1");
$d->setChar("Ashad");
//$d->display();
$d1= new Data();
$d1->setInt("2");
$d1->setChar("shahrukh");
$list = new linklist();
$list-> addData($d);
$list->addData($d1);
$list->displayy();
?>
</body>
</html>