0

我有这样的课:

class Example{
    private $a;
    private $b;

    function Example($user){
        $this->a = $user;
        $this->b = getsting();    //here is my problem
    }

    function getstring(){
        return "string".$this->a; //here I have a class variable
    }
}

如何返回值$b

4

2 回答 2

0
class Example
{
  private $a;
  private $b;

  function Example($user)
  {
    $this->userid=$user;
    $this->b=$this->getstring();    //use $this-> before the method name
  }

  function getstring()
  {
    return "string";
  }
}
于 2012-11-19T16:12:02.607 回答
0

在类内部,你需要使用$this->来引用其他函数。

$this->b = $this->getstring();

PS 是getstring,不是getsting

于 2012-11-19T16:12:52.230 回答