我有类似的课程:
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
?
答案 0 :(得分: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";
}
}
答案 1 :(得分:0)
在课堂内,您需要使用$this->
来引用其他功能。
$this->b = $this->getstring();
P.S。它是getstring
,而不是getsting
。