我尝试在 PHP 中构建堆栈,但它不起作用。为什么?
这是我看到的问题:
Warning: Missing argument 1 for object::object(), called in C:\Program Files (x86)\EasyPHP-12.1\www\tb\index.php on line 152 and defined in C:\Program Files (x86)\EasyPHP-12.1\www\tb\index.php on line 126
Notice: Undefined variable: txt in C:\Program Files (x86)\EasyPHP-12.1\www\tb\index.php on line 127
Fatal error: Call to undefined function back() in C:\Program Files (x86)\EasyPHP-12.1\www\tb\index.php on line 146
这是代码:( 我在代码中用 // 写了问题的行)
class object {
private $obj;
private $next = null;
private $back = null;
public function object($txt) { // line 126
$this->obj = $txt; // line 127
}
public function back($back) {
$this->back = $back;
}
public function next($next) {
$this->next = $next;
}
}
class stack2 extends object {
private $arr;
private $head = -1;
private $tail = 0;
public function push($txt) {
$this->head++;
$arr[$this->head] = new object($txt);
if ($this->head-1 >= $this->tail) {
$arr[$this->head].back($this->head-1); // line 146
$arr[$this->head-1].next($this->head);
}
}
}
$s = new stack2(); // line 152
$s->push(11111);
$s->push(22222);