开发者

private class Error Undefined property

开发者 https://www.devze.com 2023-02-20 01:37 出处:网络
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

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

精彩评论

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