php/e16obj.php
<?php
require_once('env.php');
outBegin('PHP objects use pointer/reference logic not copy on change');
class Node {
public $nm = '';
public $left = null;
public $right = null;
public function __construct($n) {
$this->nm = $n;
}
public function otree() {
outLi($this->nm);
outUL();
if ($this->left === null)
outLi('left null');
else
$this->left->otree();
if ($this->right === null)
outLi('right null');
else
$this->right->otree();
outULEnd();
}
}
$r = new Node('root 0');
$r->left = new Node('le 1');
outOL();
$r->otree();
$s = new Node('ri 2');
$r->right = $s;
$s->right = new Node('riRi 3');
$r->otree();
$r->right->left = new Node('riLe 4');
$r->otree();
$s->otree();
$s->nm .= ' s..u5';
$r->right->left->nm .= ' r..u6';
$r->otree();
$s->otree();
outOLend();
outEnd(__file__);
?>