
Untitled
By: a guest on
Aug 7th, 2012 | syntax:
None | size: 1.95 KB | hits: 10 | expires: Never
php acces to properties of a containing object
var aaa = new function () {
that = this;
that.bbb = 'foo';
this.ccc = new function () {
this.ddd = 'bar';
this.eee = function () {
return that.bbb+this.ddd;
}
}
}
class bbb {
public $ccc = 'bar';
function __construct () {
echo($that->aaa.$this->ccc);
}
}
class aaa {
public $that;
public $aaa = 'foo';
public $bbb;
function __construct () {
echo($this->aaa);
$this->$bbb = new bbb();
$this->$that = $this;
}
}
$a = new aaa ();
$this->bbb = new bbb ($this);
class bbb {
public $that;
function __contruct ($parent) {
$that = $parent
....
}
}
$aaa = (object)array(
'bbb' => 'foo',
'ccc' => (object) array(
'ddd' => 'bar',
'eee' => function() use(&$aaa){ $self = $aaa->ccc; return $aaa->bbb.$self->ddd; }
),
);
echo call_user_func($aaa->ccc->eee);
$aaa = (object)array(
'bbb' => 'foo',
'ccc' => (object) array(
'ddd' => 'bar',
'eee' => function() use(&$aaa) { return $aaa->bbb.$this->ddd; }
),
);
$aaa->ccc->eee = $aaa->ccc->eee->bindTo($aaa->ccc);
echo call_user_func($aaa->ccc->eee);
$tmp = function() {
$that = new stdClass();
$that->bbb = "foo";
$tmp = function() use ($that) {
$this_ = new stdClass();
$this_->ddd = "bar";
$this_->eee = function() use ($that, $this_) {
return $that->bbb . $this_->ddd;
};
return $this_;
};
$that->ccc = $tmp();
return $that;
};
$aaa = $tmp();
var_dump( call_user_func( $aaa->ccc->eee ));
//string(6) "foobar"
class bbb {
function __construct ($parrent) {
echo $parrent->ccc;
}
}
class aaa {
public $aaa = 'foo';
public $bbb;
public $ccc = 'bar';
function __construct () {
echo $this->aaa;
$this->bbb = new bbb($this);
}
}
$a = new aaa();