これは、データ要素のリストを作成するための私のコードです! この下の行には、2つのエラーがあります(同じ行にあります)
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>