2

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

4

1 回答 1

0
class A {
  private $**containigObject**;
  public function __construct($containigObject){
    $this->containigObject = $containigObject;
  }
  public function functionThatAccessOutsideObject(){
    //...
    $this->**containgObject**->b = 2;
    //...
  }

}

于 2012-10-31T05:55:39.623 回答