我试图使用魔术PHP函数将对象链接在一起。__isset不返回正确的结果
我有一个称为页面的抽象类,并且我网站中的每个页面都扩展了这个类。 在这种抽象类的构造函数我试图让用户对象是这样的:
public function __construct(){
$user = new user();
$this->user = $user->getIdentity();
$this->getHeader();
$this->switchAction();
$this->getFooter();
}
现在,在我的网页,我可以使用$这 - >用户,它工作一切正常。如果用户登录给我回的用户对象 在我的用户类,我有一个神奇的__get & __isset功能:
public function __get ($name){
switch ($name){
case 'oAlbums':
return $this->oAlbums = album::get_ar_obj($arWhere = array('user_id' => $this->id));
break;
public function __isset ($name){
switch($name){
case 'oAlbums':
echo 'magic isset called, trying to call '. $name . '<br />';
return isset($this->$name);
break;
}
}
因此,当在一个页面中,我要检查,如果用户有任何全部通过致电$this->user->oAlbums
。 如预期的那样,这将返回一个包含所有专辑对象的数组。但是,当我在我的网页做
if(empty($this->user->oAlbums))
echo 'still give smepty';
,它仍然Echo的字符串了..
为什么不工作的__isset功能?
谢谢!!像魅力一样工作 – 2013-05-01 21:03:17