empty() returning TRUE on object's non-empty property
Posted
by Michal M
on Stack Overflow
See other posts from Stack Overflow
or by Michal M
Published on 2010-06-17T09:32:09Z
Indexed on
2010/06/17
9:43 UTC
Read the original article
Hit count: 219
I've got a very weird and unexpected problem.
empty()
is returning TRUE
on a non-empty property for a reason unknown to me.
class MyObject
{
private $_property;
public function __construct($property)
{
$this->_property = $property;
}
public function __get($name)
{
$priv_name = "_{$name}";
if (isset($this->$priv_name))
{
return $this->$priv_name;
}
else
{
return NULL;
}
}
}
$obj = new MyObject('string value');
echo $obj->property; // Output 'string value'
echo empty($obj->property); // Output 1 (means, that property is empty)
Would this mean, that the __get()
magic function is not called when using empty()
?
btw. I'm running PHP version 5.0.4
© Stack Overflow or respective owner