In version 1.0, Gagawa uses empty() to check for valid arguments inside of the Attribute, Node, and FertileNode classes. If the user tried to add an attribute with a value of "0" (zero) PHP's empty() function returned true and Gagawa threw an Exception claiming the attribute value was empty. Well, in some cases you might need an element with an attribute value of zero, like so:
<div foo="0">bar</div>
This is completely legit. As it turns out, the empty() function considers the following "things" to be empty:
- "" (an empty string)
- 0 (zero as an integer)
- "0" (zero as a string)
- NULL
- FALSE
- array() (an empty array)
- var $var (a variable declared but without value)
However, in Gagawa's case the string "0" isn't empty, it's a valid value so empty() isn't the right check. The solution was to add a GagawaUtil::gagawaEmpty() function that has some special logic in it to check incoming attributes and tag types. This new gagawaEmpty() function is a modified version of code borrowed from here from PHP.net.
Enjoy.


Did you find this post helpful, or at least, interesting?