无法获取函数中变量的值。当我打印$this->var
时,它让我空洞。我在这些步骤中缺少什么?
class ModelFile extends CoreModel{
public $var;
public $var2;
public function setId() {
$this->var = '123';
}
public function getId(){
$this->setId();
var_dump($this->var); //Empty
}
}
答案 0 :(得分:0)
试试这个
class ModelFile extends CoreModel{
public $var;
public $var2;
public function setId() {
$this->var = '123';
}
public function getId(){
$this->setId();
var_dump($this->var); //Empty
}
}
**create an object of the above class and call the function getId() then it
will execute and print the var**
$model = new ModelFile();
$model->getId();