PHP objects use pointer/reference logic not copy on change

  1. root 0
  2. root 0
  3. root 0
  4. ri 2
  5. root 0
  6. ri 2 s..u5

End e16obj.php

args

e16obj.php

/home/ch45859/web/wlkl.ch/public_html/inf/php/e16obj.php

*** code does not have a span berfore first <br>***
<?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__);
?>