empty () first * calls the __isset () method, and only if it returns true the __get () method. those. your class should also implement __isset ().
eg.
<?php class Foo { public function __isset($name) { echo "Foo:__isset($name) invoked\n"; return 'bar'===$name; } public function __get($name) { echo "Foo:__get($name) invoked\n"; return 'lalala'; } } $foo = new Foo; var_dump(empty($foo->dummy)); var_dump(empty($foo->bar));
prints
Foo:__isset(dummy) invoked bool(true) Foo:__isset(bar) invoked Foo:__get(bar) invoked bool(false)
* edit: if it cannot "directly" find an available property in hashtable for the property of the object.
source share