All pastes #269541 Raw Edit

Mine

public text v1 · immutable
·published 2006-12-06 17:29 UTC
rendered paste body
class a{
    var $_name="";
    function getname() {
        return $this->_name;
    }

    function a($name) { 
        $this->_name = $name;
    }

}

class b{
    var $_name="";
    function getname() {
        return $this->_name;
    }

    function b($name) { 
        $this->_name = $name;
    }

}
$_links = array();
class link {
    // static var
    
    var $a;
    var $b;

    function link() {

        $GLOBALS['_links'][] = &$this;
    }

    // static method
    function getLinkedItem(&$s) {
        foreach($GLOBALS['_links'] as $key=>$link) {
            if ($GLOBALS['_links'][$key]->isALinkOf($s)) {
                return $GLOBALS['_links'][$key];
            }
        }
        return new link();

    }

    function isALinkOf(&$s) {
        return ($this->a === $s || $this->b === $s);
    }

    function &getA() {
        return $this->a;
    }

    function &getB() {
        return $this->b;
    }
}

$a = new a('john');
$b = new b('locke');

$link =& new link(); 
$link->a=$a;
$link->b=$b;
// Get linked item of $a

$tmp = link::getLinkedItem($a);
var_dump($tmp->a);