我无法理解这种行为:我的isset()
支票总是在肯定有值的情况下返回false !property
<?php
class User {
protected $userId; // always filled
protected $userName; // always filled
/**
* Magic method for the getters.
*
* @param type $property
* @return \self|property
*/
public function __get($property) {
if (property_exists($this, $property)) {
return $this->$property;
} else {
throw new Exception('property '.$property.' does not exist in '.__CLASS__.' class');
}
}
}
?>
当我使用以下内容从另一个类中检查此变量时:
isset($loggedUser->userName); // loggedUser is my instantiation of the User.php
它回来FALSE
了??但是当我重载__isset()
User.php 中的函数时,我会TRUE
按预期返回:
public function __isset($name)
{
return isset($this->$name);
}
只是要清楚:
echo $loggedUser->name; // result "Adis"
isset($loggedUser->name); // results in FALSE, but why?
谢谢你的帮助!