首頁  >  文章  >  後端開發  >  php面向对象有关问题?

php面向对象有关问题?

WBOY
WBOY原創
2016-06-13 13:08:18709瀏覽

php面向对象问题???
class factory{
private $tmp=array();
function __construct(){}
public function t(){
array_push($this->tmp,3);
}
public function gett(){
return $this->tmp;
}
}
$a=new factory();
print_r($a->gett());
怎么输出null,我想输出3,怎么得到

------解决方案--------------------
...fuction t(){}

没有执行过 $tmp=array(); 他就是空数组

$a=new factory();
$a->t();
print_r($a->gett());

或者
function __construct(){
array_push($this->tmp,3);
}

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn