开发者

private class Error Undefined property

Good morning everybody, I have a two class, the first accesses the second class.

More on segunta class has a private $ my, and this gives the error Undefined pro开发者_Python百科perty: session::$my in line, if($this->my)

I would be very grateful for the help.

Sample code,

class session{

  public function run_session(){
    ..run..
    data::run($line); 
 }
}


class data {

private $my = "../../my/";

   public function run($line){
     if($this->my.$line){
     ....run...
     }
  }

}


you must use like this

class data {

private $my = "../../my/";

   public function run($line){
     if($this->my.$line){   // here you are using $this, so the function must be called on object of class data
     ....run...
     }
  }

}

class session{

  public function run_session(){
    ..run..
    $data = new data();  // create object of class data, so that you can call the function run
    $data->run($line); 
 }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜