Код: Выделить всё
// The Class
class Person{
private $number;
public function __construct($num){
$this->number = $num;
}
// this the returns value, even though its a private member
public function __get($property){
return intval($this->$property);
}
}
Код: Выделить всё
// The Code
$person = new Person(5);
if (empty($person->number)){
echo "its empty";
} else {
echo "its not empty";
}
Однако это работает, если я сохраняю свойство в переменной, а затем оцениваю его.
Итак, как лучше всего определить, пусто ли свойство объекта? Спасибо.
Подробнее здесь: https://stackoverflow.com/questions/117 ... y-is-empty
Мобильная версия