我正在尝试调试我创建的类。 它总是中断并在日志中抛出 undefined variable 我找不到解决方案因为我不知道我做错了什么,我认为它应该工作但没有。
undefined变量在erase()
函数中,而不是在show()
函数中
class pepe{
private $array = array();
function show(){
$this->erase();
print_r($this->array);
}
function erase(){
print_r($this->array);
}
}
$o = new pepe();
$s = $o->show();
最佳答案
class pepe{
private $array = array();
function show(){
$this->erase();
print_r($this->array);
}
function erase(){
print_r($this->array);
}
}
$o = new pepe();
$s = pepe->show();
你为什么在这里调用佩佩?应该是这样的:
class pepe{
private $array = array();
function show(){
$this->erase();
print_r($this->array);
}
function erase(){
print_r($this->array);
}
}
$o = new pepe();
$s = $o->show();
你必须打电话
$o->show()
因为你已经将 pepe 分配给了
$o
关于php - undefined variable PHP 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30365195/