I have a class that overrides __get before returning a value. How come it always returns true for empty()? It acts like if __call returns a value after the function empty rather than before.
<?php
class ref_dummy {
private $_data = array();
public function __get($name) {
if (array_key_exists($name, $this->_data)) return $this->_data[$name];
$this->_data[$name] = 'bar'; // load sample data
return $this->_data[$name];
}
}
$dummy = new ref_dummy();
if (empty($dummy->foo)) echo 'is empty' . '<br/>';
else echo $dummy->foo . '<br/>';
?>
I know if($dummy->foo) works but I'm wondering why empty() doesn't.