Hejsa!
I have a scope problem. My program should say, first "list empty", then "list not empty" - but says "list empty" twice. Help! Where should I say global - or what? I've tried to copy the php/oop example, but I seem to need something more.
[lisea@asterix llist]$ cat IntNode.obj
<?php
// a node in an integer singly linked list class
class IntNode {
var $info; // integer
var $next; // IntNode
function IntNode($i,$n) {
$this->info = $i;
$this->next = $n;
}
}
?>
[lisea@asterix llist]$
[lisea@asterix llist]$ cat IntSLList.obj
<?php
include "IntNode.obj";
// singly linked list class to store integers
class IntSSList {
var $head; // IntNode
var $tail; // IntNode
function IntSLList() {
$head = null;
$tail = null;
}
function isEmpty() {
return ($head == null);
}
function addToHead($el) {
$head = new IntNode($el,$head);
if ($tail == null) {
$tail = $head;
}
}
function printAll() {
$tmp = $head;
while ($tmp != null) {
print $tmp->info;
$tmp = $tmp->next;
}
}
}
?>
[lisea@asterix llist]$
[lisea@asterix llist]$ cat test.php
<?php
// include "IntNode.obj";
include "IntSLList.obj";
$test1 = new IntNode(2,null);
$test2 = new IntNode(3,$test1);
$test3 = new IntSSList();
if ($test3->isEmpty()) {
print "list empty<br />";
} else {
print "list not empty<br />";
}
$test3->addToHead(4);
if ($test3->isEmpty()) {
print "list empty<br />";
} else {
print "list not empty<br />";
}
$test3->printAll();
?>
<html><head><title>Hej verden</title></head>
<body>
Hej verden
</body>
</html>
[lisea@asterix llist]$
Thanks in advance for any help I can get!
Lise