(experienced in PHP 5.6.3) The `empty()` can't evaluate `__get()` results explicitly, so the `empty()` statement bellow always renders true
<?php
class Juice extends Liquid{
protected $apple;
protected $orange;
public function __get($name) {
return $this->$name;
}
public function __construct($apple, $orange) {
$this->apple = $apple;
$this->orange = $orange;
}
}
class Glass {
protected $liquid;
public function __get($name) {
return $name == "liquid" ? $this->liquid : false;
}
public function __construct() {
$this->juice = new Juice(3, 5);
}
}
$glass = new Glass();
var_dump(empty($this->liquid->apple));
?>
The correct way is to force the evaluation of `__get()` first, by using extra braces around implicit statements like this:
<?php
var_dump(empty(($this->liquid->apple)));
?>
So if you are using packages that utilize object oriented designs and magic methods like `__get()`, it's a good practice to always use double braces for `empty()` calls.