On Jun 3, 2011, at 1:38 PM, Matt Pelmear wrote: > 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 -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php