note 79784 added to function.empty
| From: | Anonymous at osu1 dot php dot net | Date: | Wed, 12 Dec 2007 19:00:16 +0000 |
| Subject: | note 79784 added to function.empty | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-133396@lists.php.net to get a copy of this message | ||
According to the PHP bug repository the following behavior of empty isn't a bug, it's
"a feature."
If you use the __get function with an object and then test a property of that object with empty()
you will ALWAYS get false. You don't even get the benefit of an error or warning like you do
when you try something like
empty(someFunction());
So instead you find yourself with the wonderful fun of tracing program flow. Beware using empty
with objects. Better yet, use this one line wrapper function
function isEmpty($value) { return empty($value) }
This dodges the stupidity of the current implementation of empty() entirely. If you try to evaluate
a property of an object set by __get in any way it will work with this wrapper function.
----
Server IP: 69.147.83.197
Probable Submitter: 76.123.217.162
----
Manual Page -- http://www.php.net/manual/en/function.empty.php
Edit -- https://master.php.net/note/edit/79784
Del: integrated -- https://master.php.net/note/delete/79784/integrated
Del: useless -- https://master.php.net/note/delete/79784/useless
Del: bad code -- https://master.php.net/note/delete/79784/bad+code
Del: spam -- https://master.php.net/note/delete/79784/spam
Del: non-english -- https://master.php.net/note/delete/79784/non-english
Del: in docs -- https://master.php.net/note/delete/79784/in+docs
Del: other reasons-- https://master.php.net/note/delete/79784
Reject -- https://master.php.net/note/reject/79784
Search -- https://master.php.net/manage/user-notes.php