演出道具有哪些:php5类使用的问题

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/09 01:33:26
<?
class mList {
var $e;
var $pNext = mList;
}

class ListEx {
var $head = mList;
var $tail = mList;

function Init() {
$this->head = NULL;
$this->tail = NULL;
}

function Terminate() {
$this->ClearList();
}

function MakeNewNode($e) {
$n = new mList();
$n->e = $e;
if($this->head == NULL) {
$this->head = $n;
}
else {
$this->head->pNext = $n;
}
$this->tail = n;
$this->tail->pNext = NULL;
}

function TransferList($list2) {
$list2 = new mList();
$list2->head = $this->head;
$list2->tail = $this->tail;
$this->head = NULL;
$this->tail = NULL;
}

function GetNode($e) {
if($this->head != NULL) {
$n = $this->head;
$e = $n->e;
$this->head = $this->head->pNext;
if($this->head == NULL) {
$this->tail = NULL;
}
$n = NULL;
}
}

function HasNode() {
return $this->head == NULL;
}

function ClearList() {
while($this->head != NULL) {
$n = $this->head;
$this->head = $this->head->pNext;
$n = NULL;
}
}

function DisplayList() {
$n = $this->head;
while($n != NULL) {
echo $n->e . "<br>\n";
$n = $n->pNext;
}
}
}

echo "List:<p>\n";
$l = new ListEx();
for($i = 0; $i < 9; $i++) {
$l->MakeNewNode("test" . i);
}
$l->DisplayList();
?>

错误提示:
Warning: Attempt to assign property of non-object in e:\PHP\Stack\INDEX.PHP on line 27

Warning: Attempt to assign property of non-object in e:\PHP\Stack\INDEX.PHP on line 30

Warning: Attempt to assign property of non-object in e:\PHP\Stack\INDEX.PHP on line 27

Warning: Attempt to assign property of non-object in e:\PHP\Stack\INDEX.PHP on line 30
………………

很明显是在$this->head->pNext = $n这里出错了,那就是说head并不是mList类,所以没有pNext这个成员,请问要如何声明才能使用呢?或是php根本不支持?

太难了

好难啊