我是 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 类的属性和方法