我有一个小问题。在 javascript 中可以转发范围:
var aaa = new function () {
that = this;
that.bbb = 'foo';
this.ccc = new function () {
this.ddd = 'bar';
this.eee = function () {
return that.bbb+this.ddd;
}
}
}
aaa.ccc.eee() 将返回“foobar”。我怎样才能在 PHP 中做一些具有相同效果的事情?我有一个代码:
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
....
}
}
?