我是php的新手,我想知道为什么这不起作用:
class A {
private $containigObject;
public function __construct($containigObject){
$this->containigObject = $containigObject;
}
public function functionThatAccessOutsideObject(){
//...
$this->containgObject->b = 2;
//...
}
}
class B {
public $b = 1;
public function someFunction(){
//...
$a = new A($this);
$a->functionThatAccessOutsideObject();
//...
}
}
$b = new B();
$b->someFunction();
我正在尝试使用A类中B类的属性和方法
答案 0 :(得分:0)
class A {
private $**containigObject**;
public function __construct($containigObject){
$this->containigObject = $containigObject;
}
public function functionThatAccessOutsideObject(){
//...
$this->**containgObject**->b = 2;
//...
}
}