Lowest Common Ancestor

function commonAncestor($a, $b)
{
  $continue = true;
  while ($continue) {
    $aA = $a->getA();
    $aB = $b->getA();

    print "$aA $aB\n" ;

    if ($aA == $aB) {
      return $aB;
    }

    if ($aA < $aB) {
      $a = new x($aB);
    }
    else {
      $b = new x($aA);
    }
  }
}

var_dump(commonAncestor(new x(4), new x(5)));

class x
{
  public $value = null;

  public function __construct($value)
  {
    $this->value = $value;
  }

  public function getA()
  {
    if($this->value == 0) {
      $this->value = 0;
      return 0;
    }

    if($this->value == 2) {
      $this->value = 0;
      return 0;
    }

    if($this->value == 1){
      $this->value = 0;
      return 0;
    }

    if($this->value == 4) {
      $this->value = 1;
      return 1;
    }

    if($this->value == 3) {
      $this->value = 1;
      return 1;
    }

    if($this->value == 6) {
      $this->value = 3;
      return 3;
    }

    if($this->value == 5) {
      $this->value = 3;
      return 3;
    }

    return false;
  }
}
    
index