Hello,
I discovered today that the DOMNode::getAttribute() function (which is
undocumented on the php site) returns an empty string if the requested
attribute doesn't exist in the node.
From the source:
if (value == NULL) {
RETURN_EMPTY_STRING();
} else {
RETVAL_STRING((char *)value, 1);
xmlFree(value);
}
Seems to me that it should return NULL. (That's what libxml does, apparently.)
Does anyone know of a particular reason it returns an empty string instead?
Does anyone know of a particular reason it is not documented?
(I'd be happy to document and provide the ridiculously simple patch of
returning NULL...)
Thanks,
-Matt
Does anyone know of a particular reason it is not documented?
(I'd be happy to document and provide the ridiculously simple patch of
returning NULL...)
Greetings Matt,
Documenting DOM is messy/tricky (and underdocumented), but:
Here's one option to begin helping out with the PHP documentation:
And please write phpdoc@lists.php.net for additional documentation related details and/or questions.
Regards,
Philip
Hello,
I discovered today that the DOMNode::getAttribute() function (which is
undocumented on the php site) returns an empty string if the requested
attribute doesn't exist in the node.From the source:
if (value == NULL) {
RETURN_EMPTY_STRING();
} else {
RETVAL_STRING((char *)value, 1);
xmlFree(value);
}Seems to me that it should return NULL. (That's what libxml does, apparently.)
Does anyone know of a particular reason it returns an empty string instead?
Does anyone know of a particular reason it is not documented?
(I'd be happy to document and provide the ridiculously simple patch of
returning NULL...)
We match the behaviour the w3c defines for the DOM.
DOMString
The Attr value as a string, or the empty string if that attribute does not have a specified or default value.
Consider using hasAttribute() if you care about the existence.
- Scott
Hello,
I discovered today that the DOMNode::getAttribute() function (which is
undocumented on the php site)
It's DOMElement::getAttribute()...
returns an empty string if the requested
attribute doesn't exist in the node.
Yes, but that's in line with the W3C DOM spec!
David