Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:52873 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 57245 invoked from network); 3 Jun 2011 21:44:16 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Jun 2011 21:44:16 -0000 Authentication-Results: pb1.pair.com header.from=scott@macvicar.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=scott@macvicar.net; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain macvicar.net from 74.125.83.170 cause and error) X-PHP-List-Original-Sender: scott@macvicar.net X-Host-Fingerprint: 74.125.83.170 mail-pv0-f170.google.com Received: from [74.125.83.170] ([74.125.83.170:60758] helo=mail-pv0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/60-08509-EA559ED4 for ; Fri, 03 Jun 2011 17:44:15 -0400 Received: by pvh21 with SMTP id 21so1142638pvh.29 for ; Fri, 03 Jun 2011 14:44:11 -0700 (PDT) Received: by 10.142.229.4 with SMTP id b4mr566262wfh.171.1307137451136; Fri, 03 Jun 2011 14:44:11 -0700 (PDT) Received: from [172.24.140.69] ([66.220.144.74]) by mx.google.com with ESMTPS id f3sm1744466pbj.0.2011.06.03.14.44.10 (version=SSLv3 cipher=OTHER); Fri, 03 Jun 2011 14:44:10 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1084) Content-Type: text/plain; charset=us-ascii In-Reply-To: Date: Fri, 3 Jun 2011 14:44:09 -0700 Cc: internals@lists.php.net Content-Transfer-Encoding: quoted-printable Message-ID: References: To: Matt Pelmear X-Mailer: Apple Mail (2.1084) Subject: Re: [PHP-DEV] DOMNode::getAttribute() From: scott@macvicar.net (Scott MacVicar) On Jun 3, 2011, at 1:38 PM, Matt Pelmear wrote: > Hello, >=20 > 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. >=20 > =46rom the source: > if (value =3D=3D NULL) { > RETURN_EMPTY_STRING(); > } else { > RETVAL_STRING((char *)value, 1); > xmlFree(value); > } >=20 > Seems to me that it should return NULL. (That's what libxml does, = apparently.) >=20 > 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=