Ciao a tutti,
ho un problema con uno script in php5...non posso utilizzarlo perchè devo metterlo su aruba ed aruba non supporta il php5 ma solo il 4. Dovrei adattarlo al php4 sempre se è possibile...ma spero tanto di si!!
L'errore me lo da nella pagina 1 in questo punto


function w() {
if($this->sons == NULL)
return 1;

$sum = 0;

for($i=0; $i<$this->sons->countSons(); $i++) {
$sum += $this->sons->at($i)->w();
}

return $sum;
}

ed è questo:

Parse error: parse error in c:\programmi\easyphp1-8\www\magda\tree\Node.php on line 31

Linea 31: $sum += $this->sons->at($i)->w();


posto le tre pagine che formano il mio script... questo script serve per generare una sorta di diagramma di flusso.

-------------------------------------------------------------------------------
pagina uno: Node.php


<?php
require_once("NodeList.php");

class Node {
var $content; // int char string...
var $sons; // NodeList

function __construct($c) {
$content = $c; // int char string ...
$sons = NULL; // NodeList
}

function addSon($son) { // $son : Node
if($this->sons == NULL) {
$this->sons = new NodeList($son);
$this->sons->content = $son;
$this->sons->next = NULL;
return;
}

$this->sons->add($son);
}

function w() {
if($this->sons == NULL)
return 1;

$sum = 0;

for($i=0; $i<$this->sons->countSons(); $i++) {
$sum += $this->sons->at($i)->w();
}

return $sum;
}

function h() {
if($this->sons == NULL)
return 1;

$max = 0;
for($i=0; $i<($this->sons->countSons()); $i++) {
$sonh = 1+$this->sons->at($i)->h();
if($sonh > $max)
$max = $sonh;
}

return $max;
}

function printNode() {
echo "".$this->content." w:".$this->w()." h:".$this->h()."
";

if($this->sons != NULL) {
for($i=0; $i<($this->sons->countSons()); $i++) {
$this->sons->at($i)->printNode();
}
}
}

}
?>
----------------------------------------------------------------------------------------
pagina 2: NodeList.php

<?php
require_once("Node.php");

class NodeList {
var $content; // : Node
var $next; // : NodeList

function __construct($c) {
$this->content = $c;
$this->next = NULL;
}

function at($i) { // : Node
if($i==0)
return $this->content;

if($this->next == NULL)
return NULL;

$i--;

return $this->next->at($i);
}

function add($n) { // $n : Node
if($this->next==NULL) {
$this->next = new NodeList($n);
$this->next->content = $n;
$this->next->next = NULL;
//$n->next = NULL;
return;
}

return $this->next->add($n);
}

function remove($n) {
// TODO
}

function countSons() {
if($this->next == NULL)
return 1;

return 1+($this->next->countSons());
}
}
?>

----------------------------------------------------------------------------------------

pagina 3: index.php

<html>
<head>
<title>Tree</title>
</head>

<body>
<?php
require_once("Node.php");

echo "Output

";

$a = new Node(0);
$a->content = 'A';

$b = new Node(0);
$b->content = 'B';
$a->addSon($b);

$e = new Node(0);
$e->content = 'E';
$b->addSon($e);

$c = new Node(0);
$c->content = 'C';
$a->addSon($c);

$d = new Node(0);
$d->content = 'D';
$a->addSon($d);

$f = new Node(0);
$f->content = 'F';
$d->addSon($f);

$g = new Node(0);
$g->content = 'G';
$d->addSon($g);

$h = new Node(0);
$h->content = 'H';
$g->addSon($h);


$root = $a;
$root->printNode();

function getStyle($color, $w, $ml) {
echo "position:absolute; border:1px solid #000; padding:3px; margin:3px; text-align:center; width:$w; background:$color; margin-left: $ml;";
}
?>




<h3>Immagine con un albero di esempio</h3>

</p>




<h3>Rappresentazione dell'albero</h3>
<div style="<?=getStyle('#ccf', '800px', '0%');?>">
A
<div style="diplay:inline; <?=getStyle('#aac', '22%', '0%');?>">
B
<div style="<?=getStyle('#99a', '90%', '0%');?>">
E
</div>
</div>
<div style="diplay:inline; <?=getStyle('#aac', '22%', '25%');?>">
C
</div>
<div style="diplay:inline; <?=getStyle('#aac', '44%', '50%');?>">
D
<div style="diplay:inline; <?=getStyle('#99a', '44%', '0%');?>">
F
</div>
<div style="diplay:inline; <?=getStyle('#99a', '44%', '50%');?>">
G
</div>
</div>
</div>
</p>

</body>
</html>

-------------------------------------------------------------------------------
Grazie a tutti!