Re: DOMNode::getAttribute()
| From: | Scott MacVicar | Date: | Fri, 03 Jun 2011 21:44:09 +0000 |
| Subject: | Re: DOMNode::getAttribute() | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-52873@lists.php.net to get a copy of this message | ||
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